array: Key casts

<?php
$array = array(
    1    => "a",
    "1"  => "b",
    1.5  => "c",
    true => "d",
);
var_dump($array);
?>
  • Strings containing valid decimal integers, unless the number is preceded by a + sign, will be cast to the integer type .
  • Floats are also cast to integers, which means that the fractional part will be truncated.
  • Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
  • Null will be cast to the empty string, i.e. the key null will actually be stored under "".
  • Arrays and objects can not be used as keys.

array: Key casts — Structure map

Clickable & Draggable!

array: Key casts — Related pages: