The problem is that the first time through the inner loop, you're replacing $lts[$i]
with $lts[$i][$j]
. When the loop repeats, it tests $j < count($lts[$i])
. But $lts[$i]
is no longer an array, it's the value from the first column of the row, so you get this error.
You can solve this by assigning count($lts[$i])
to a variable before the loop. But that just raises another problem. When you try to do $lts[$i] = $lts[$i][$j]
in subsequent iterations, $lts[$i]
is still not an array, so there's no $j
element of it.
You can solve that by using foreach
instead of for
, since it makes a copy of the array it's looping over.
for($i=0; $i<count($lts); $i++){
foreach ($lts[$i] as $col)
$lts[$i] = $col;
}
}
But it's not clear what the point of the inner loop is. Each iteration just overwrites $lts[$i]
with the next column, so the final result will just be the last column. You can do that without the inner loop.
foreach ($lts as &$row) {
$row = end($row);
}
or simply:
$lts = array_map('end', $lts);