I'm confused by something I just ran into in a script I was working on. I had the following:
function getPart($part)
{
$array = array('a', 'b', 'c');
if ($part == 'first') $part = 0;
if ($part == 'last') $part = count($array) - 1;
if (isset($array[$part])) return $array[$part];
return false;
}
$position = 0;
echo getPart($position);
So, if I were to try the string "first", I should get "a" as the output. With the string "last" I should get "c" and so on. When I run the script above, with PHP 5.3, I get "c" ...
Confused, I ran a quick test ...
var_dump(0 == 'first');
var_dump(0 == 'last');
Both return TRUE
... WHY??? I am so confused by this behavior!