array merge php with same index

2020-04-19 06:00发布

I have this situation:

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

How can I get this?

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

Thanks for the answers

3条回答
啃猪蹄的小仙女
2楼-- · 2020-04-19 06:41

try with

$res = array_merge_recursive($qty, $price);
print_r($res);
查看更多
家丑人穷心不美
3楼-- · 2020-04-19 06:46
$qty = array("qty"=>"35254" );
$price = array ( "price"=> "1000" );

$combine = array_merge($qty,$price);
var_dump($combine);
查看更多
\"骚年 ilove
4楼-- · 2020-04-19 06:53

May be it's that you want:

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

The result :

array(1) {[0] => array(2) { 'qty' => string(5) "35254" 'price' => string(4) "1000" } }
查看更多
登录 后发表回答