0

I've been unable to find an elegant solution to what is a simple problem.

Basically an API call I'm making is outputting one empty array before my main set of data. What would be the fastest way of removing this from the data set?

Array structure...

$example = Array (
) Array (
[aaa] => Array (
[aa] => aa
[aa] => aa
[aa] => aa
[aa] => aa
)

Therefore the first array() needs to be removed to be:

$fixed = Array (
[aaa] => Array (
[aa] => aa
[aa] => aa
[aa] => aa
[aa] => aa
)

Thanks, Phil

Phil Hudson
  • 3,819
  • 8
  • 35
  • 59
  • possible duplicate of [Remove empty array elements](http://stackoverflow.com/questions/3654295/remove-empty-array-elements) – superphonic Jul 03 '14 at 12:04
  • not an array element, removing whole empty arrays – Phil Hudson Jul 03 '14 at 12:05
  • how are you getting your data? example of data may be helpful. `array() array(multidimensionalstartshere(), array());` doesn't make any sense. – bansi Jul 03 '14 at 12:31

2 Answers2

0
$fixed = array_filter($example);

Remove empty array elements

Community
  • 1
  • 1
superphonic
  • 7,954
  • 6
  • 30
  • 63
0
unset($example[0]);

Wouldn't that be easy?

Or if it's associative

reset($example);
unset($example[key($example)];
Dalai Lama
  • 404
  • 4
  • 20