Home PHP How to remove all 0's (zeros) from an PHP array?
 
 
 

How to remove all 0's (zeros) from an PHP array?

PDF Print E-mail

Question: How to remove all 0's (zeros) from an PHP array?

Example:

If I have the following PHP array

$array = array(9,0,6,4,5,0,9,0,0,0);
and I need to have all 0's removed from it.

 

Answer:

  • Use the PHP array_filter function. If you don't supply a callback function it will filter out all values that are equal to false

    $new_array = array_filter($array);

+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!