1

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?

2
  • well for starters array_merge can take more than two arguments. the rest depends on what you have in getData. Commented Jan 6, 2014 at 1:51
  • There is nuanced advice to give depending on context. Does getData() return indexed data or associative data? We don't have a minimal reproducible example, so we can't confidently give appropriate advice. Commented Feb 12 at 4:12

1 Answer 1

2

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.