Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #12333
| Message-ID | <1895038.mY5GtRscxT@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-12-20 16:35 +0100 |
| Subject | Re: foreach problem part two |
| Newsgroups | comp.lang.php |
| References | (2 earlier) <y1yigdragnyw$.c2kv48q50osj.dlg@40tude.net> <52b398d2$0$9503$9b4e6d93@newsspool1.arcor-online.net> <t6ds31so68b7.1s80a7lxre6po$.dlg@40tude.net> <2QPsu.177440$4q1.100708@en-nntp-12.dc1.easynews.com> <l91car$jg8$1@dont-email.me> |
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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
foreach problem part two richard <noreply@example.com> - 2013-12-19 13:41 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-19 20:00 +0100
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-19 19:16 +0000
Re: foreach problem part two The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:21 +0000
Re: foreach problem part two The Natural Philosopher <tnp@invalid.invalid> - 2013-12-19 19:20 +0000
Re: foreach problem part two Evan Platt <evan@theobvious.espphotography.com.invalid> - 2013-12-19 23:07 -0800
Re: foreach problem part two Scott Johnson <noonehome@chalupasworld.com> - 2013-12-20 00:59 -0800
fixed! (was: foreach problem part two) richard <noreply@example.com> - 2013-12-19 16:07 -0500
Re: fixed! (was: foreach problem part two) Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:48 +0000
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-19 22:34 +0000
Re: foreach problem part two richard <noreply@example.com> - 2013-12-19 18:39 -0500
Re: foreach problem part two Jerry Stuckle <jstucklex@attglobal.net> - 2013-12-19 19:51 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2013-12-20 02:09 +0100
Re: foreach problem part two richard <noreply@example.com> - 2013-12-19 23:05 -0500
Re: foreach problem part two Richard Damon <Richard@Damon-Family.org> - 2013-12-19 23:37 -0500
Re: foreach problem part two Norman Peelman <npeelman@cfl.rr.com> - 2013-12-20 07:14 -0500
Re: foreach problem part two Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-20 16:35 +0100
Re: foreach problem part two Norman Peelman <npeelman@cfl.rr.com> - 2013-12-20 07:11 -0500
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-20 13:17 +0000
Re: foreach problem part two Evan Platt <evan@theobvious.espphotography.com.invalid> - 2013-12-20 09:14 -0800
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:52 +0000
Re: foreach problem part two John Smith <johnsmithjsm@live.com> - 2014-01-06 23:13 -0500
Re: foreach problem part two Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-07 10:07 +0100
Re: foreach problem part two Doug Miller <doug_at_milmac_dot_com@example.com> - 2013-12-20 03:11 +0000
Re: foreach problem part two Arno Welzel <usenet@arnowelzel.de> - 2013-12-20 07:52 +0100
Re: foreach problem part two Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-20 18:37 +0000
csiph-web