RE: [PHP] learning php - problem already
| From: | Ford, Mike [LSS] | Date: | Fri, 01 Aug 2003 07:52:49 +0000 |
| Subject: | RE: [PHP] learning php - problem already | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-157896@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: CPT John W. Holmes [mailto:holmes072000@charter.net]
> Sent: 31 July 2003 15:54
> you basically
> have this:
>
> list($k,$v,$key,$value) = array(1=>'abc', 'value'=>'abc',
> 0=>'a',
> 'key'=>'a');
>
> So, how this works is that list starts with $value. $value is
> at position
> number four, so since arrays start at zero, it's going to
> look in the array
> that was passed for an element at [3]. Since there is no [3]
> in the passed
> array, you get a NOTICE about undefined offset.
>
> Next it moves on to $key and looks for element [2]. Again you
> get a warning
> since there is no element [2] in the passed array.
>
> Next is $v and list is looking for [1]. Since [1] does exist
> and has a value
> of 'abc', now $v = 'abc'
>
> Last is $k and [0] and you get $k = 'a'.
>
> That's how it works. :)
>
> That's why this code:
>
> list($a, $b, $c, $d) = array(4=>'four', 3=>'three',
> 2=>'two',
> 1=>'one',
> 0=>'zero');
> echo "$a, $b, $c, $d";
>
> gives:
>
> zero, one, two, three
Ho, thanks for that -- I must admit I hardly ever use each() or list(), and
taking a quick look at the current manual page for list() does seem to have
changed quite a bit since I originally read it -- so I guess my
understanding of it was faulty. I still think it's quite confusing -- your
explanation here is much better -- so I might see if I can't put together
something even better for incorporation in the manual!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211