You are here: Re: [PHP] PHP bug within multi. dimensional arrays? « PHP « IT news, forums, messages
Re: [PHP] PHP bug within multi. dimensional arrays?

Posted by Richard Davey on 06/06/05 17:11

Hello Merlin,

Monday, June 6, 2005, 2:51:39 PM, you wrote:

M> while ($row = mysql_fetch_object($result)){
M> $cat[$row->main_id][name] = $row->main_name;
M> $cat[$row->main_id][$row->sub_id][name] =
M> $row->sub_name;
M> }

Quote array keys.. ALWAYS quote them:

$cat[$blah]['name'] = $whatever

Otherwise PHP will think [name] is trying to use a constant and
substitute a value accordingly.

M> foreach ($cat AS $maincat){
M> echo $maincat[name].':';
M> foreach($maincat AS $subcat){
M> echo $subcat[name].$br;
M> }
M> echo $br;
M> }

M> As you can see I get the extra letters N and E. Is this an php
M> error or did I do something wrong?

You did something wrong ;) If you don't quote the array keys it'll
assume a constant, which in turn would assume a 1 which will give you
the first character of the string.

Best regards,

Richard Davey
--
http://www.launchcode.co.uk - PHP Development Services
"I do not fear computers. I fear the lack of them." - Isaac Asimov

 

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

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