php数组的合并

数组的合并:  array_merge()     两个数组的元素会合并成一个数组的元素


数组的合并:

例:

$a = array(
              'where' => 'uid=1',
              'order' => 'uid',
             );
   $b = array(
              'where' => 'uid=2',
              'order' => 'uid desc',
            );


 $c = array_merge($a,$b);
   print_r($c);

输出结果为:

Array ( [where] => uid=2 [order] => uid desc )

如果两个数组存在相同的key,则后面那个会覆盖前面的


$c=array_merge($b,$a);

输出结果为:

Array ( [where] => uid=1 [order] => uid )


$c = $a + $b;

print_r($c);

输出结果为:

Array ( [where] => uid=1 [order] => uid )

+操作符,如果两个数组存在相同的key,则前面那个会覆盖后面的


$c = $b + $a;

print_t($c);

输出结果为:

Array ( [where] => uid=2 [order] => uid desc )



如果是数组索引:

  $a = array(
              1 => 'uid=1',
              2 => 'uid',
             );
   $b = array(
              1 => 'uid=2',
              3 => 'uid desc',
            );
   $c = array_merge($a,$b);
   print_r($c);


输出结果为:

Array ( [0] => uid=1 [1] => uid [2] => uid=2 [3] => uid desc )


类似于foreach每个数组元素,然后将其压入新的堆栈中


$c = array_merge($b,$a);

print_r($c);

输出结果为:

Array ( [0] => uid=2 [1] => uid desc [2] => uid=1 [3] => uid


$c = $a + $b;

print_r($c);

输出结果为:

Array ( [1] => uid=1 [2] => uid [3] => uid desc )


+类似于foreach,但是遇到相同的key,则不再处理


$c = $b + $a;

print_r($c);

输出结果为:

Array ( [1] => uid=2 [3] => uid desc [2] => uid )



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值