I have an array in the below format.
array (
0 =>
array (
'safe_route' => 'yes',
'route_name' => 'route_1',
'route_risk_score' => '2.5'),
1 =>
array (
'safe_route' => 'no',
'route_name' => 'route_2',
'route_risk_score' => '3.5'),
2 =>
array (
'safe_route' => 'no',
'route_name' => 'route_3',
'route_risk_score' => '4.5')
)
i need to loop it and remove the key 'route_risk_score' with its value inside all arrays. How this can be done in php. Am new to php.Help would be appreciated
To delete element in original array, use a reference to each element:
// see this & in front of `$item`?
// It means that `$item` is a reference to element in original array
// and unset will remove key in element of original array, not in copy
foreach($array as &$item) {
unset($item['route_risk_score']);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With