Here, my array is sometimes 1D or 2D. From my array, I need to remove some of the keys. Lets say for now my array is like below:
array:2 [
0 => array:8 [
"picture_id" => "1"
"color_name" => "Black"
"color_code" => "#000000"
]
1 => array:8 [
"picture_id" => "1"
"color_name" => "Red"
"color_code" => "#ff0000"
]
]
I have following lines of code, here I check if the array is 1D or 2D. And based on that, I am trying to unset my array.
$remainingArray = Helpers::removedSelectedKeys($groupedInputs, ["picture_id"]);
public static function removedSelectedKeys(array $array, array $keys)
{
array_map(function ($key) use (&$array) {
if (Helpers::isMulti($array)) {
foreach ($array as $item) {
unset($item[$key]);
}
} elseif (array_key_exists($key, $array)) {
unset($array[$key]);
}
}, $keys);
return $array;
}
public static function isMulti($array)
{
return (count($array) != count($array, 1));
}
But its not working. Can anybody please help what mistake I am doing?