-1

The title says it all. I want to delete the highlighted section in yellow as shown in picture below. And rest remain unchanged. What is the best way to do it? Is there a method that does't use foreach?

enter image description here

Moby M
  • 910
  • 2
  • 7
  • 26
begineeeerrrr
  • 323
  • 2
  • 7
  • 17
  • See this question, https://stackoverflow.com/questions/4466159/delete-element-from-multidimensional-array-based-on-value – Sagar Gautam Aug 11 '17 at 05:24

3 Answers3

2

you can do this just with one foreach!

foreach ($data as $key => $subArr) {
    unset($subArr['id']);
    $data[$key] = $subArr;  
}
2

You can use the following

$filteredArray = array_map(function($array) {
    unset($array['id']);
    return $array;
}, $dataArray);
chanafdo
  • 5,016
  • 3
  • 29
  • 46
1

Instead of doing foreach() loop on the array, You can go with array_search()

$results=array_search($unwantedValue,$array,true);
if($results !== false) {
  unset($array[$result]);   
}
Moby M
  • 910
  • 2
  • 7
  • 26