0

I've been searching and haven't found an answer yet to my question.

Say I want to create a menu out of three or more arrays, but I don't what elements will those arrays have.

I have something like this:

$arr1 = array(
   'design' => 'Link 1'
);

$arr2 = array(
   'development' => 'Link 2'
);

$arr3 = array(
   'design' => 'Link 3',
   'seo' => 'Link 4'
);

What can I do to turn those three arrays into this:

$final_array = array(
   'development' => 'Link 2',
   'seo' => 'Link 4',
   'design' => array(
         '0' => 'Link 1',
         '1' => 'Link 3'
     ),
);
2

1 Answer 1

4

array_merge_recursive()

$arr1 = array(
   'design' => 'Link 1'
);

$arr2 = array(
   'development' => 'Link 2'
);

$arr3 = array(
   'design' => 'Link 3',
   'seo' => 'Link 4'
);

$newarr = array_merge_recursive($arr1, $arr2, $arr3);
print_r($newarr);
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.