Ângelo Rigo
Ângelo Rigo

Reputation: 2165

Cakephp 2 hash function to generate a new array

Hi i do receive an array in this format :

array (size=2)
  0 => 
    array (size=1)
      22 => string 'One string' (length=20)
  1 => 
    array (size=1)
      8 => string 'Another string' (length=17)

How can i use cakephp hash to create another array usign 8 and 22 as indexes :

  array (size=2)
        22 => string 'One string' (length=20)
        8 => string 'Another string' (length=17)

I try hash::nest but the result is :

array (size=2)
  0 => 
    array (size=3)
      0 => string 'One string' (length=17)
      'children' => 
        array (size=0)
          empty
      1 => string 'Another string' (length=20)
  1 => 
    array (size=3)
      0 => string 'One string' (length=17)
      'children' => 
        array (size=0)
          empty
      1 => string 'Another string' (length=20)

Upvotes: 0

Views: 59

Answers (1)

bill
bill

Reputation: 1656

This can be done with Hash::merge

$formattedArray = Hash::merge($array[0], $array[1]);

Upvotes: 1

Related Questions