合并两个数组有一个共同的键

时间:2012-08-21 04:08:40

标签: php arrays json merge

我有两个Json数组:

$arrayA = array("avg" => '1',"shape" => 'hey');

$arrayB = array("avg" => '2',"shape" => 'trapezoid');

我希望使用javascriptPHP将它们组合为:

arrayAB = {"avg":['1', '2'], "shape":[hey', 'trapezoid']};  

1 个答案:

答案 0 :(得分:0)

$arrayA = array("avg" => "234","shape" => "hey");
$arrayB = array("avg" => "5678","shape" => "trapezoid");
$array3 = array();

foreach ($arrayA as $key => $value) {
    $array3[$key] = array($arrayA[$key], $arrayB[$key]);
}