RE: using result of function in same line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've never seen a language where you couldn't do things like "echo foo() ;"
and I've seen a good many languages.  It's so universal, I don't know that
it has a name, other than "expression evaluation".   Language processors
typically evaluate inner subexpressions first, then use the value in
evaluating the containing expression.  

That said, I'm still pretty new to PHP, so as far as I know PHP may be
deficient in that capability.


-----Original Message-----
From: Igor Belagorudsky [mailto:iggy1@hotmail.com] 
Sent: Wednesday, November 05, 2003 7:27 PM
To: php-windows@lists.php.net
Subject:  using result of function in same line


ok here's the problem - in some languages (like javascript or c# for
instance) you could use the results of a function in same line as your call.
say you have a function foo that returns an array, you can do something like

print foo()[4];

this will print the 5th element of whatever array foo returned. but in php,
it seems like you have to break it up into 2 calls like this:

$x = foo();
echo $x[4];

i find it hard to believe that you can't do

echo foo()[4];

so... how can u go about this?

thanks,
igor

and also, what is that called when you can do it in same line?

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux