Reply to Re: undefined array index question

Your name:

Reply:


Posted by Oli Filth on 09/17/05 21:33

petermichaux@yahoo.com said the following on 17/09/2005 17:47:
> Hi,
>
> I am curious about how php deals with the following situation where I
> use an undefined index into an array. PHP seems to be behaving exactly
> how I want it to but I want to make sure that it is not a fluke. It
> seems like most programming languages would crash if you used an
> undefined index. Why does PHP work the way it does?
>
> My example is below
>
> Thanks,
> Peter
>
> <?php
>
> $array['foo']=3;
> echo 'M'.$array['foo'].'M';
> //How can I index into the array to an index that doesn't exist?
> echo 'M'.$array['bar'].'M';
>
> //output
> //M3MMM
> //note there is no space between the last two M's
> //this is exactly the result I want but why does it work?
> ?>
>

The only reason nothing breaks is because you must have PHP
error-reporing disabled.

If you had error-reporting enabled, you'd see a message like:

Notice: Undefined index: bar in D:\htdocs\Test\08.php on line 5

--
Oli

[Back to original 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

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