use a var inside a function

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2007
Igal
 
Posts: n/a
Default use a var inside a function

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?

Reply With Quote
  #2 (permalink)  
Old 01-06-2007
Myron Turner
 
Posts: n/a
Default Re: use a var inside a function

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0