return function

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
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

return function

Post by nincha »

whats the syntax to return multible values within a function????
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

i use to return an array with those values
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

return $vars = array($var1, $var2, $var3, etc);

later:

$vars = myfunction();
Malder
Forum Newbie
Posts: 13
Joined: Wed Mar 19, 2003 11:09 pm

Post by Malder »

And will this work if variables are of different types?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Your array can store any type of variables you want:

$my_array[] = new Object(); // an object
$my_array[] = new array(); // an array
$my_array[] = "a string"; // a string ;-)
$my_array[] = 1; // an int
$my_array[] = false; // a boolean
$my_array[] = 3.14; // a float

$my_array[0] returns an object
$my_array[1] returns an array
$my_array[2] returns a string
$my_array[3] returns an int
$my_array[4] returns a boolean
$my_array[5] returns a float

So, yes, you can keep multiple types in an array
Post Reply