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

1 Answer 1

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>";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.