FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » foreach problem part two
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: foreach problem part two [message #184295 is a reply to message #184292] Fri, 20 December 2013 15:35 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Norman Peelman wrote:

> This is not 100% legal syntax because the second [0] acts as a string
> offset instead of an index:
>
> $alist[0][0] = "data";
> Fatal error: Cannot use string offset as an array... you must use
> *array()* to set these up.

Unsurprisingly, utter nonsense from you again.

$ php -r '$a[0] = 42; var_dump($a["0"]);'
int(42)

In fact,

$alist[0][0] = "data";

is equivalent to

$alist = array(array("data"));

or

$alist = array(0 => array("data"));

or

$alist = array(array(0 => "data"));

or

$alist = array(0 => array(0 => "data"));

or variations of that where the key is the string '0' or "0", if $alist did
not exist before.

It is equivalent to

$alist[0] = array("data");

and variations of that, including those where the keys are '0', if $alist
existed before but did not have an element with key 0.

And it is equivalent to itself if $alist[0] referred to an array before
(i.e., it modifies the element with index 0 of the array that is the element
with index 0 of the outer array).

That you can create „multi-dimensional“ arrays, which can even be
associative, with just one line, is the beauty of PHP.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP sql entry is a godaweful mess
Next Topic: Math Formula Question - Need Ideas
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 17:27:11 GMT 2024

Total time taken to generate the page: 0.04418 seconds