数组合并php与相同的索引

时间:2014-10-17 13:23:26

标签: php arrays zend-framework

我遇到这种情况:

$qty = array(1) {[0]=> array(1) { ["qty"]=> string(5) "35254" }
$price = array(1) {[0]=> array(1) { ["price"]=> string(5) "1000" }

我怎么能得到这个?

$res = array(1) {[0]=> array(1) { ["qty"]=> string(5) "35254" ["price"]=> string(5) "1000"}

感谢您的回答

3 个答案:

答案 0 :(得分:2)

$qty = array("qty"=>"35254" );
$price = array ( "price"=> "1000" );

$combine = array_merge($qty,$price);
var_dump($combine);

答案 1 :(得分:2)

可能是你想要的:

$res = array();
foreach($qty as $k => $v){
    $res[$k] = array_merge($qty[$k],$price[$k]);
}

结果:

array(1) {[0] => array(2) { 'qty' => string(5) "35254" 'price' => string(4) "1000" } }

答案 2 :(得分:0)

尝试

$res = array_merge_recursive($qty, $price);
print_r($res);