I have a multi dimensional array like below.
array:1 [
0 => array:3 [
"picture_id" => "0"
"car_name" => "CA"
"from" => "2020"
"to" => "2020"
]
]
I need to remove from
& to
from the above array and return result in same structure.
I have tried following code
$whitelist = array("from", "to");
$finalArray = [];
foreach ($records as $record) {
foreach ($record as $key => $item) {
if (!in_array($key, $whitelist)) {
$finalArray[$key] = $item;
}
}
}
But the result I am getting is not multi-dimensional array like this:
array:1 [
"picture_id" => "0"
"car_name" => "CA"
]
My expected result is:
array:1 [
0 => array:3 [
"picture_id" => "0"
"car_name" => "CA"
]
]