user3616435 user3616435 - 3 months ago 17
PHP Question

Insert data into a multidimensional array in php

I am stuck in a simple problem. I have two arrays:

$array1 = array ( productcode => 218133, categoryid => 315, color => red )
$array2 = (10,220)


How to merge this two arrays to have the below result?

$array1 = array ( productcode => 218133, categoryid => array (315, 10, 220), color => red )

Answer
$array1 = array ( 'productcode' => 218133, 'categoryid' => 315, 'color' => 'red' );
$array2 = array (10,220);

$array1['categoryid'] = array_merge((array)$array1['categoryid'], $array2);
print_r($array1);

Demo