[nycphp-talk] Accessing non-existent array elements ok?
Darryle Steplight
dsteplight at gmail.com
Sun Aug 17 17:00:01 EDT 2008
Hi Michael,
Unless you like seeing that error message it is not ok. If you do
print "<pre>";
print_r($a);
print"</pre>";
,you will get a very good detailed visual of your array content.
You're array only has one key/value pair. Try
$a = array('a' => 'b', 'b' => 'b2', 'c' => 'b3' );
followed by the rest of your code and you should be good to go.
On Sun, Aug 17, 2008 at 4:49 PM, Michael B Allen <ioplex at gmail.com> wrote:
> I seem to recall getting a warning trying to access array elements
> that did not exist but I can't seem to trigger that issue right now.
>
> The following code:
>
> <?php
> $a = array('a' => 'b');
> $result = $a['c'];
> var_dump($result);
>
> yields the following:
>
> $ php -f t.php
> NULL
>
> Is it ok to access non-existent array elements?
>
> Will accessing an array element using a key that does not exist always
> return NULL?
>
> Mike
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
More information about the talk
mailing list