Delete an (exact) element from an array in php

Posted by Holian on Stack Overflow See other posts from Stack Overflow or by Holian
Published on 2010-03-17T13:53:42Z Indexed on 2010/03/17 14:01 UTC
Read the original article Hit count: 127

Filed under:
|
|

Hi Masters!

For example i have an array like this:

  $test= array("0" => "412", "1" => "2"); 

I would like to delete the element if its = 2

 $delete=2;
   for($j=0;$j<$dbj;$j++) {
       if (in_array($delete, $test)) {  
       unset($test[$j]);
    }
    }
    print_r($test);

But with this, unfortunatelly the array will empty...

How can i delete an exact element from the array?

Thank you

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays