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
Navigation:
[Reply to this message]
|