Functions returning arrays

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
Glycerine
Forum Commoner
Posts: 39
Joined: Wed May 07, 2008 2:11 pm

Functions returning arrays

Post by Glycerine »

U have a function of which returns an array - simple enough.

Is there a way to reference it by simply:

Code: Select all

$myvar = somefunc()[0]
Thanks in advance.
shaneiadt
Forum Newbie
Posts: 10
Joined: Sat Mar 15, 2008 9:26 pm

Re: Functions returning arrays

Post by shaneiadt »

Code: Select all

$myvar = somefunc()[0];
Nope you can't do this!! Just assign the returned array to an array variable;

Code: Select all

 
$myarray = someFunc();
$myvar = $myarray[0];
 
Then you can use $myvar variable as normal;
echo $myvar;
or whatever valid way you want to do it :)
Glycerine
Forum Commoner
Posts: 39
Joined: Wed May 07, 2008 2:11 pm

Re: Functions returning arrays

Post by Glycerine »

cool. I thought as much. I was just trying to find a prettier way to reference an array return from a function
Post Reply