remove subarrays in an array php

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"];

>Solution :

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>";

Leave a Reply