When:
$person = array('name' => 'bill');
isset($person['jibberish'])
evaluates to FALSE.
But:
$person = 'bill';
isset($person['jibberish'])
evaluates to TRUE, as $person['jibberish']
returns the first character of string $person.
Is this as intended? This came as a shocker to me today, as I've always used empty($array['key'])
without ever including is_array()
in my if statements.
Because $person
is a string, the array-like-index is converted to an int
.
(int)'any non-numeric string in the world' == 0
So, you "naturally" get the first character of any string if you use a random, non-numeric string as the index.
Cause you are printing the undefined index of the string, not array. If you try to print indexes of strings in PHP, you'll have the each character of the string:
$person = 'bill';
$person[0] //b
$person[1] //i
$person[2] //l
$person[3] //l