0

I'm using a foreach to build this :

array (size=3)
  'trainid' => string '76795' (length=5)
  'traintype' => string ' -X' (length=3)
  'userid' => string 'CPN' (length=3)

array (size=3)
  'trainid' => string '27725' (length=5)
  'traintype' => string ' -Z' (length=3)
  'userid' => string 'CPN' (length=3)

array (size=0)
  empty

array (size=3)
  'trainid' => string '00000' (length=5)
  'traintype' => string ' -X' (length=3)
  'userid' => string 'CPN' (length=3)

array (size=3)
  'trainid' => string '27921' (length=5)
  'traintype' => string ' -Z' (length=3)
  'userid' => string 'CPN' (length=3)

And as you see, there is an empty array and I would like to entirely remove this array. In fact, it crashs my sql script if there is an empty array.

Do you know how to remove it?

Thank you!

0

2 Answers 2

1

You can use array_filter, if no callback is provided, all entries equal to FALSE will be removed.

$array2 = array_filter($array);
Sign up to request clarification or add additional context in comments.

3 Comments

Already tried. Using this does not remove the empty array.
Can you copy the content of var_dump($array)?
@SausauRJ check - eval.in/446056
0

Simply use array_filter(), It will automatically remove empty variable in array..

   print_r(array_filter($arrayvariable));

1 Comment

Already tried. Using this does not remove the empty array.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.