theoretical PHP arrays
| From: | stefano federici | Date: | Wed, 30 May 2007 22:02:53 +0000 |
| Subject: | theoretical PHP arrays | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-29969@lists.php.net to get a copy of this message | ||
Hi,
I trying to find a reason why array functions are not allowed to be used as normal arrays. To
clarify, I'm allowed to write
$arr = array( "maria", "mario", "luigi", "luisa");
echo $arr[1];
but I'm not allowed to write
echo array( "maria", "mario", "luigi", "luisa")[1];
In PHP documentation I read that "array" is a language construct, not a function. So this
may be the reason. But I also tried with
echo (explode (" ", "maria mario luigi luisa"))[1];
and this doesn't work either (even if "explode" is a function). Not surprisingly,
$arr = explode (" ", "maria mario luigi luisa");
echo $arr[1];
does work. So, if I can straightforwardly divide by, say, 2 the integer output by a function, why
shouldn't I be allowed to straightforwardly use the array output by a function?
This is not something completely weird that I'm asking. In Visual Basic (that I know
mustn't be the most loved programming language for PHP users) you can say
print array( "maria", "mario", "luigi", "luisa")(1)
Maybe is THIS the reason why it doesn't work in PHP? ;-)
Thanks for your consideration and help
Stefano
Stefano Federici
-------------------------------------------------
Università degli Studi di Cagliari
Facoltà di Scienze della Formazione
Dipartimento di Scienze Pedagogiche e Filosofiche
Via Is Mirrionis 1, 09123 Cagliari, Italia
-------------------------------------------------
Tel: +39 349 818 1955 Fax: +39 070 937 1870