I have the example array :
$a = [
"foo1",
"faa2",
"foo3",
"fuu4",
"faa5",
"foo6",
...,
"fuuX",
];
By example, I want remove all element of this array beginning by "foo" and "faa". The expected result must be :
$removes = [
"foo",
"faa"
]
// some processes
var_dump($a);
/* show
$a = [
"fuu4",
...,
"fuuX",
];
*/
In my example, the $remove
array contain 2 entries. But in my real case, this array may contains X entries.
How can I remove entries in main array ($a
in the example) depending of the beginning of array's values (contained in another array, $removes
in my example)
Thanks for help !
EDIT : I can do something like this :
foreach($a as $key=>$entry){
foreach($removes as $remove){
if(strpos($entry, $remove) === 0){
unset($a[$key]);
break:
}
}
}
But I think (maybe I'm wrong) there is a better solution (more proper, and more fast for php execution time). Maybe is there a way for avoid a double foreach