I have this array:
$array = [
['b', 'd', 'c', 'a', ''],
['c', 'a', 'd', '', ''],
['b', 'd', 'a', '', ''],
['c', 'd', 'a', 'b', '']
];
and need to delete (unset?) all elements where value is "c" so that one ends up with:
$array = [
['b', 'd', 'a', ''],
['a', 'd', '', ''],
['b', 'd', 'a', '', ''],
['d', 'a', 'b', '']
];
The element gets removed, and the other elements to shift up. I know that unset does not re-index the array. Cannot get to unset for all multidimensional arrays, but only with one array. Can the arrays be re-indexed afterwards?
The code BELOW removes elements where the value is equal to "c" but the index of the first element is not re-indexed. Can anyone suggest a solution to re-indexing the inner arrays?
$i = 0;
foreach ($array as $val)
{
foreach ($val as $key => $final_val)
{
if ($final_val == "$search_value")
{
unset($array[$i][$key]);
}
}
$i = $i + 1;
}