I am using PHP and I have an array of user images that I need to filter. I need to do 2 different filters:
Images Array:
Array
(
[0] => smiles.gif
[1] => kittens.jpg
[2] => biscuits.png
[3] => butthead.jpg
)
$bad_words = array('beavis','butthead','winehouse');
$bad_extensions = array('.gif','.tiff');
I would like it to return:
Array
(
[0] => kittens.jpg
[1] => biscuits.png
)
$array = array("smiles.gif", "kittens.jpg", "biscuits.png", "butthead.jpg");
$new_arr = array_filter($array, "filter");
function filter($element) {
$bad_words = array('beavis','butthead','winehouse');
$bad_extensions = array('gif','tiff');
list($name, $extension) = explode(".", $element);
if(in_array($name, $bad_words))
return;
if(in_array($extension, $bad_extensions))
return;
return $element;
}
echo "<pre>";
print_r($new_arr);
echo "</pre>";
Outputs
Array
(
[1] => kittens.jpg
[2] => biscuits.png
)
I removed the . from your extensions tho
edit: added wicked fleas correction