-3

I have an array like this

There are more arrays inside the array that I need to remove

$arr = [
  "4",
  "10" => [
    [
      "id" => "standard", 
      "name" => "Standard"
    ],
    [
      "id" => "standard_2.0", 
      "name" => "Standard 2.0"
      ]
  ],
  "11" => [
    [
      "id" => "gold", 
      "name" => "Gold"
    ],
    [
      "id" => "gold_2.0", 
      "name" => "Gold 2.0"
      ]
  ],
];

How can I remove all subarrays so that it stays like this?

$arr = ["4", "10", "11"];
Hector
  • 17
  • 6
  • 2
    What have you tried so far? – Blackhole Mar 25 '23 at 13:20
  • 1
    Does this answer your question? [PHP: Get key from array?](https://stackoverflow.com/questions/3317856/php-get-key-from-array) – Sanmeet Mar 28 '23 at 16:28
  • Might want to check https://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php – silveiralexf Mar 29 '23 at 08:01
  • Does this answer your question? [How to remove duplicate values from a multi-dimensional array in PHP](https://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php) – silveiralexf Mar 29 '23 at 08:01

1 Answers1

1

You can do it like this :

foreach ($arr as $key => $value) {
   
   if(is_array($value)){
    $newarray[] = $key;
   }else{
     $newarray[] = $value;
   }
  
}
 echo "<pre>";
print_r($newarray);
echo "</pre>";
Anant V
  • 299
  • 1
  • 9