0

I have two separate array. Now I want to create multidimensional array using existing two array. This is my two separate array -

Array
(
[0] => 11
[1] => 22
[2] => 33
[3] => 44
)

-------------------
    Array
(
[0] => 555
[1] => 666
[2] => 777
[3] => 888
)

I want result in multidimensional array, that is -

Array
(



[0] => Array
    (
        [0] => 11
        [demoid] => 11
        [1] => 555
        [demovalue] => 555
    )
    [1] => Array
    (
        [0] => 22
        [demoid] => 22
        [1] => 666
        [demovalue] => 666
    )
    [2] => Array
    (
        [0] => 33
        [demoid] => 33
        [1] => 777
        [demovalue] => 777
    )
)
2
  • Do you have some code actually attempting to combine them? You should at least try Commented Jan 15, 2014 at 11:44
  • Why do you need both numeric and named keys for each value? Commented Jan 15, 2014 at 11:47

1 Answer 1

2

Just loop around and add the values into a new array - I don't see why you would struggle to do so...

$new_array = array();
foreach($array1 as $key => $val) {
    $new_array[] = array(   0 => $val,
                            'demoid' => $val,
                            1 => $array2[$key],
                            'demovalue' => $array2[$key]);
}
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.