Question

I created this working code using array_merge in php.

getData() is returning an array.

    $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?

Was it helpful?

Solution

array_merge() accepts multiple arguments:

$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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top