I Have Two Arrays.
$uploaded_array = array("image/jpeg", "image/jpeg", "image/gif", "image/png", "text/html");
$allowed_array = array("image/jpeg", "image/gif", "image/png");
I need a function to achieve a specific goal. The Conditions are, 1. uploaded_array can only contain elements from allowed_array. 2. it is okay for uploaded_array to not contain all the elements present in allowed_array but the uploaded_array should not contain any element which is not present in the allowed_array. 3. it is also okay for uploaded_array to have duplicates element as long as the element is present in allowed_array too.
I am just storing the uploaded images file type into uploaded_array and then i have defined allowed_array to set acceptable file type formats.
Thanks for the answers.
Found one solution by myself. just eliminated duplicates from the first array and compared the two arrays for the difference and then count the difference. if the count is more then 0 it means the first array had an element which is not present in the second array.
$uploaded_array = array_unique(array("image/jpeg", "image/jpeg", "image/gif", "image/png", "text/html"));
$allowed_array = array("image/jpeg", "image/gif", "image/png");
$acceptable_format=count(array_diff($uploaded_array,$allowed_array));
if($acceptable_format==0) {
//all files are acceptable
} else {
//some files are not in valid format
}