I have a while loop in a function and need to know the value of one variable which is defined in the 'root' part of the php code - i.e. above the function itself.
It looks like I can't read its value from that while loop so I have to define it again before the loop but in the same function. Any solution?
Thanks!
Tomas[/mysql_man]
[SOLVED] How to access variable from within function?
Moderator: General Moderators
-
tomfra
- Forum Contributor
- Posts: 126
- Joined: Wed Jun 23, 2004 12:56 pm
- Location: Prague, Czech Republic
[SOLVED] How to access variable from within function?
Last edited by tomfra on Sun Jul 04, 2004 12:24 pm, edited 1 time in total.
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Try ...
Code: Select all
function yourfunction() {
global $variable_you_need;
while.......or instead of global you can use autoglobal $GLOBALS table
Code: Select all
<?php
function yourfunction(){
while...
$use_here=$GLOBALS["variable_you_need"]
}
?>