douqianxun8540 2018-07-07 10:52
浏览 269

哪一个更优选array_push()或array_merge(),当一个数组为空而另一个数组有一些值时

I am new to php ,facing some issues between array_push and array_merge

I used two array in input $a(Blank array) and $b(Associative array with some value)

In case of array_merge

when i used array_merge i got same result in both cases ($c and $f) but in put i used an associative array with key "212" and value "aa" but in output i get an array with key "0" and value "aa"

now in case of

array_push i get 2 different outputs (int 1 and int 2)for two different cases for 2 same inputs

I tried this

$a=array();
$b= array(212=>"aa");
$c=array_merge($a,$b);
$f=array_merge($b,$a);
$d=array_push($b,$a);
$e=array_push($a,$b);

now i dumped these array using this

echo '<pre>';
var_dump($c);
var_dump($f);
var_dump($d);
var_dump($e);

and i get these result for every array

array(1) {
  [0]=>
  string(2) "aa"
}
array(1) {
  [0]=>
  string(2) "aa"
}
int(2)
int(1)
  • 写回答

1条回答 默认 最新

  • dse55384 2018-07-07 11:02
    关注

    This answer is duplicated if I can say.

    Can you check this link

    What is the difference between array_push() and array_merge()?

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名