You make this all go away

Been a while. Have a simple one – what does this print?

$arr[null] = "Null string";
$arr[false] = "False string";
$arr[0] = "Zero string";
 
print_r($arr);


It’s…

Array ( [] => Null string [0] => Zero string )

Surprise!

It gets better:

$arr[null] = "Null string";
$arr[false] = "False string";
$arr[0] = "Zero string";
$arr[''] = "Empty string string";

gives

Array ( [] => Empty string string [0] => Zero string )

Hat tip to Will for this one.

2 Responses to “You make this all go away”

  1. Kit says:

    So, why? Why does changing the keys change which of them print?

  2. Owen Jacobson says:

    1. FALSE is sometimes zero.
    2. null is sometimes ”.

    Never quite exactly, but close enough for arrays.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped=""> (Syntax highlighting)