简体   繁体   English

在PHP中更好的方法来array_merge?

[英]Better way to array_merge in php?

I created this working code using array_merge in php. 我在php中使用array_merge创建了此工作代码。

getData() is returning an array. getData()返回一个数组。

    $cars = array();


    $cars = array_merge($cars, $this->getData($x, $y, $z, 0, -1));
    $cars = array_merge($cars, $this->getData($x, $y, $z, 1, -1));
    $cars = array_merge($cars, $this->getData($x, $y, $z, 1, 0));
    $cars = array_merge($cars, $this->getData($x, $y, $z, 1, 1));

There is a better way to do the same? 有没有更好的方法可以做到这一点?

array_merge() accepts multiple arguments: array_merge()接受多个参数:

$cars = array_merge($this->getData($x, $y, $z, 0, -1),
                    $this->getData($x, $y, $z, 1, -1),
                    $this->getData($x, $y, $z, 1, 0),
                    $this->getData($x, $y, $z, 1, 1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM