I'm finding myself doing a lot of things with associative arrays in PHP.
I was doing this:
foreach ($item as $key=>$value)
{
if ($arr[$key] == null)
{
$arr[$key] = 0;
}
$arr[$key] += $other_arr[$value];
}
But then I realised that it works fine if I exclude the line that initializes $arr[$key], presumably since it's null which is treated as the same as 0.
Is making that kind of assumption safe in php? And if it's safe, is it a good idea?
Thanks,
Ben