Why use !== FALSE to check stripos in php?

后端 未结 5 558
别跟我提以往
别跟我提以往 2020-12-10 11:32

Here is the code I am looking at.

foreach ($header as $idx => $field) {
    if (stripos($field, \'foo\') !== false) {
        $cols[\'foo\'] = $idx;
             


        
5条回答
  •  春和景丽
    2020-12-10 11:57

    Dunno if something like this would be easier to maintain. Depends if you do something else in those if conditions. But you can set the keys in a config file, db, pass as argument to your function, or similar.

    $keys = array(
        'foo',
        'bar',
        'brr',
        'ffo',
    );
    foreach ($header as $idx => $field) {
        foreach ($keys as $key) {
            if (stripos($field, $key) !== false) {
                $cols[$key] = $idx;
                break;
            }
        }
    }
    

提交回复
热议问题