Remove all elements in array matching a specific string using PHP

后端 未结 2 1994
情深已故
情深已故 2021-01-04 10:00

I\'m hoping this is really simple, and I\'m missing something obvious!

I\'m trying to remove all elements in an array that match a certain string. It\'s a basic 1D a

2条回答
  •  一生所求
    2021-01-04 10:04

    You need to use a callback.

    array_filter($array, function($e){
       return stripos("Remove", $e)===false
    });
    

    To understand above code properly see this commented code.

    array_filter($array, function($e){
        if(stripos("Remove", $e)===false) // "Remove" is not found
            return true; // true to keep it.
        else
            return false; // false to filter it. 
    });
    

提交回复
热议问题