In case the array contains less than four elements...

PHP Code:
$n count($foo2[1]);
for (
$i max(0$n 4); $i $n; ++$i)
{
  
//...