3 ms·
I note that some languages effectively do the array-padding by default. In PHP, accessing an out-of-bounds element results in a Notice (not even a Warning, let
by oneeyedpigeon 8y ago
I note that some languages effectively do the array-padding by default. In PHP, accessing an out-of-bounds element results in a Notice (not even a Warning, let alone an Error) and a NULL return value. Of course, in an integer context, NULL gets coerced to 0, so the following will work just fine:
$input = array(1, 3, 4, 5, 0, 1, 8);
$i = 0;
echo $input[$i - 1] + $input[$i + 1];
// outputs 3