0

I have an array that looks like this. Imagine there are 10 other keys like "Divertissement" in the principal array (this is only one branch of the principal array).

 array (size=8)
 'Divertissement' => 
    array (size=3)
  'Cosmic Top' => 
    array (size=3)
      'Cat' => string '7' (length=1)
      'Prix' => string '2.99' (length=4)
      'Desc' => string 'SOME TEXT'
  'Episodes' => 
    array (size=3)
      'Cat' => string '7' (length=1)
      'Prix' => string '3.99' (length=4)
      'Desc' => string 'SOME TEXT"
  'Rocket Deal' => 
    array (size=3)
      'Cat' => string '7' (length=1)
      'Prix' => string '0.99' (length=4)
      'Desc' => string SOME TEXT" 

I am trying with no succes to create a new array that removes the first level array for each branch. So it would just remove "Divertissement", and start directty at Cosmic Top, Episodes, Rocket Deal as first level arrays.

3 Answers 3

3

Just merge every top-level entry to a new array:

$newArray = array();

foreach($yourArray as $item)
{

    $newArray = array_merge($newArray, $item);

}
Sign up to request clarification or add additional context in comments.

5 Comments

was about to suggest exactly that
I don't get it :(. Can you use the elements of my array so I can understand better?
@Maxwell: sorry, I forgot to assign the merged value on each iteration, see my edit.
Nvm I got it! Thanks it works like a char, even though I don,t really get how it works lol.
Oh shit, I just got how it works, awesome function! Thanks again!
1

Just pop it off:

$array = array_pop($array);

Comments

0

You could assign the array key values to a new array:

$newArray = $currentArray['Divertissement'];

Comments

Your Answer

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