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

Home » Imported messages » comp.lang.php » illegal offset problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: illegal offset problem [message #184050 is a reply to message #184039] Tue, 03 December 2013 22:25 Go to previous messageGo to previous message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma:
Senior Member
On Tue, 03 Dec 2013 08:55:20 -0600, Robert Heller wrote:

> At Tue, 03 Dec 2013 14:16:38 +0000 Paul Herber <paul(at)pherber(dot)com> wrote:
>
>>
>> On Tue, 3 Dec 2013 09:00:50 -0500, richard <noreply(at)example(dot)com> wrote:
>>
>>>
>>> foreach ($six0 as $item){
>>>
>>> $year=$six0[$item]['year'];
>>> echo $year;
>>>
>>>
>>> }
>>>
>>> If $item is an illegal offset, then what is the proper way to retrieve the
>>> value of a 2d array?
>>
>> RTFM
>> http://us1.php.net/manual/en/language.types.array.php
>>
>> There is an example of foreach with a 2D array halfway down the page.
>> FFS.
>
> Note: *technically* PHP (like C and all of the other C-like languages) does
> not have multi-dimensional arrays (in the sense FORTRAN's multi-dimensional
> arrays). (Using OO coding it is possible to create true multi-dimensional
> array as a new class, typically by allocating a 1D block of memory and
> overloading the () or [] operators.) Instead, it can have an array of arrays
> (in C it would be an array of pointers), which 'fakes' 2 (or more) dimensional
> arrays. So the correct code for the above would be (the foreach does the array
> element dereferencing automatically):
>
> foreach ($six0 as $item){
> $year=$item['year'];
> echo $year;
> }
>
> OR (more verbosely, getting the keys (indexes) explicity)
>
> foreach ($six0 as $itemkey => $item) {
> $year=$six0[$itemkey]['year']; /* $item IS $six0[$itemkey]! */
> echo $year;
> }
>
>>
>>
>>

}

foreach ($six0 as $itemkey => $item) {
$song=$six0[$itemkey]['track'];
echo "<div>$song</div>";};

works fine. shows all songs for every year.

}

foreach ($six0 as $itemkey => $item) {
$song=$six0[$itemkey]['track'];
if ($year==$show){ echo "<div>$song</div>";}
}

Show nothing. Why?

http://mroldies.net/test/menu4.html
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Can I download file with address like this "http://***.com/file.php/ABC.html" automatically ?
Next Topic: request for error checking feature
Goto Forum:
  

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

Current Time: Thu Nov 28 09:34:06 GMT 2024

Total time taken to generate the page: 0.04198 seconds