You are here: Re: Multidimensional associated array « PHP Programming Language « IT news, forums, messages
Re: Multidimensional associated array

Posted by Norman Peelman on 01/12/08 05:14

Jerry Stuckle wrote:
> Kurda Yon wrote:
>> Hi,
>>
>> I try to construct an array such that each element of it is another
>> array returned by the fetch_array_function:
>>
>> for ( $i = 1; $i<=$n; $i++ )
>> {
>> $ar[$i] = mysql_fetch_array( $result );
>> print "$ar[$i][fieldname]\n";
>> }
>>
>> It prints "Array[fieldname]".
>>
>> If I replace $ar[$i] by $ar everything works fine! Could you pleas
>> help me with that?
>>
>
> print $ar[$i]['fieldname'] . "\n";
> or
> print "{$ar[$i]['fieldname']}\n";
>
> [fieldname] will give you an E_NOTICE if enabled (and it should be on
> your development system).
>

A notice is not thrown in this case because the key is already within
double quotes. The problem is fixed by the necessity to use { }'s when
using multi-dimensional arrays within double quotes. I normally use this
method. To get PHP to throw a NOTICE, remove the single quotes from your
second example.

--
Norman
Registered Linux user #461062

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация