array_filter()
removes all entries of the array that equals FALSE
, thereby creating a gap in your array.
This is what $sch2
contains:
Array
(
[0] => moving
[1] => on
[2] =>
[3] => my
[4] => car
)
When you apply array_filter()
on $sch2
, you'll get an array that looks like this:
Array
(
[0] => moving
[1] => on
[3] => my
[4] => car
)
As you can see, index 2
is not defined. You need to re-index the array numerically for this to work. You can use array_values()
for this purpose:
$sch = array_values(array_filter($sch2));