assigning a variable to a function that returns value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cmartin19
Forum Newbie
Posts: 5
Joined: Thu May 15, 2008 8:07 pm

assigning a variable to a function that returns value

Post 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:
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: assigning a variable to a function that returns value

Post by lafever »

Code: Select all

 
 
function get_id() {
return 5;
}
 
$the_id = get_id();
echo $the_id;
 
cmartin19
Forum Newbie
Posts: 5
Joined: Thu May 15, 2008 8:07 pm

Re: assigning a variable to a function that returns value

Post by cmartin19 »

thank you!
Post Reply