1

There are two arrays:

$arr1 = array
(
    [0] => A
    [1] => B
    [2] => C
    [3] => D
)

$arr2 = array
(
    [0] => d
    [1] => e
    [2] => f
)

I want to make a multidimensional array that would look something like this:

$arr3 = array
(
    [0] => A => array
           (
                [0] => d
                [1] => e
                [2] => f
           )
    [1] => B
    [2] => C
    [3] => D
)

I guess first array's value should be the key of the second array.

3 Answers 3

1

This should do the trick:

$arr3 = $arr1;
$arr3[0] = array('A' => $arr2);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it does a trick. Though like this $arr3[0] = array($arr3[0] => $arr2) no need to know a value of first array's selected position. Thanks man!
0

If you want to set dynamicaly then you can use:

$arr3 = $arr1;
$arr3[0] = array($arr3[0] => $arr2);

Comments

0
$arr1 = array('A','B','C','D');
$arr2 = array('d','e','f');
$array = $arr1;
$array[0] = array($arr1[0]=>$arr2);
var_dump($array);

Please see https://eval.in/645288

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.