0

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)

1 Answer 1

1

This can be done with Hash::merge

$formattedArray = Hash::merge($array[0], $array[1]);
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.