Page 1 of 1

assigning a variable to a function that returns value

Posted: Fri May 16, 2008 1:12 am
by cmartin19
I'm wondering if php functions have return types like asp.net functions. I'm trying to get a php function to return a value by assigning it to a variable like in the following example:

$the_id = get_id();
function get_id()
{
echo 5;
}
echo $the_id;

The problem is the function will not assign a return value to $the_id, it will show a blank where the 5 should be.

get_id() will show the number 5.

Is there a way to get the function get_id() to assign the value of 5 to $the_id variable? Thanks, cm :crazy:

Re: assigning a variable to a function that returns value

Posted: Fri May 16, 2008 1:25 am
by lafever

Code: Select all

 
 
function get_id() {
return 5;
}
 
$the_id = get_id();
echo $the_id;
 

Re: assigning a variable to a function that returns value

Posted: Fri May 16, 2008 8:54 am
by cmartin19
thank you!