我在php中使用array_merge创建了这个工作代码。
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));
还有更好的方法吗?
答案 0 :(得分:1)
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));