This is a discussion on use a var inside a function within the PHP General forums, part of the PHP Programming Forums category; hay. fastest way to explain will be just give example. $vid = 5 function test() { $my_vid_inside_function = $vid } i want that $my_vid_inside_function ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Igal wrote:
> hay. fastest way to explain will be just give example. > > $vid = 5 > > function test() { > $my_vid_inside_function = $vid > } > > i want that $my_vid_inside_function will be equal to 5. > in other words, how i use an outside var inside a function? > <?php $vid = 5; test_ref($vid); // pass in $vid as a reference test_glob(); // access $vid as a global function test_ref(&$vid) { $my_vid_inside_function = $vid; echo "Ref: $my_vid_inside_function\n"; } function test_glob() { global $vid; $my_vid_inside_function = $vid; echo "Global: $my_vid_inside_function\n"; } /* Result: Ref: 5 Global: 5 */ ?> -- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ |