user1834464
user1834464

Reputation:

Building a simple array

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.

Upvotes: 0

Views: 47

Answers (3)

Carl Owens
Carl Owens

Reputation: 1292

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

$newArray = $currentArray['Divertissement'];

Upvotes: 0

moonwave99
moonwave99

Reputation: 22817

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

$newArray = array();

foreach($yourArray as $item)
{

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

}

Upvotes: 3

Petah
Petah

Reputation: 46050

Just pop it off:

$array = array_pop($array);

Upvotes: 1

Related Questions