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 #184053 is a reply to message #184050] Tue, 03 December 2013 23:16 Go to previous messageGo to previous message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma:
Member
At Tue, 3 Dec 2013 17:25:49 -0500 richard <noreply(at)example(dot)com> wrote:

>
> 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?

Because $year != $show. What are $year's and $show's values?

>
> http://mroldies.net/test/menu4.html
>
>

--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
[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: Sat Jun 29 07:48:32 GMT 2024

Total time taken to generate the page: 0.03936 seconds