0

i have a function to filter unwanted values in array (usually false and empty values) here it is :

function filter_array($arr ,  $filter = array('' , FALSE)){

    foreach($arr as $k=>$v)
    {
        if(in_array(trim($v) , $filter)) 
        unset($arr[$k]);
    }

    return $arr;
}

here is the problem , it considering 0 as false and removing them from array ... how can i fix this ?

one way is to loop trough $filter and and use === to check the values but i want to avoid another loop

1
  • 1
    Read the manual. Strict comparison is in the third argument. Commented Jul 2, 2014 at 2:50

1 Answer 1

1

in_array takes a third optional argument for strict comparison.

in_array(trim($v) , $filter, true)
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.