0

I've an associated array with 20 elements whose child array looks like

(int) 2 => array(
    'Comment' => array(
        'id' => '5',
        'user_id' => '13',
        'time' => '2012-05-18 14:47:36'
    ),
    'User' => array(
        'name' => 'User name'
    )
)

Now I want to extract the field name from its child array User with cakephp's set utility and append it to the child array Comment. Is there a one way step to do this other than using a for or foreach loop?

(int) 2 => array(
    'Comment' => array(
        'id' => '5',
        'user_id' => '13',
        'time' => '2012-05-18 14:47:36',
        'name =>'User name'
    )
)

1 Answer 1

1

It doesn't answer your question, but doing this with a foreach is a one way step too:

foreach ($arrays as $array)
  $array['Comment']['name'] = $array['User']['name'];

I believe there's no need to use some utility, just for the sake of using an utility.
Especially that it'll do a foreach itself.

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.