You can make a reusable function for your requirement which accepts three parametres your main array($mainArray), your required valid elements array($reqArray), and the restricted invalid elements array($restrictArray). And then return the status from this function to your main calling function. like this
public function getStatus($mainArray,$reqArray,$restrictArray){
$status = true;
foreach ($array as $num){
if(in_array($num,$reqArray) && !in_array($num,$restrictArray)){
$status = false;
break;
}
}
return $status;
}
and in your main function you can call this reusable function like this
public function mainFunction(){
$array = array("1","2","11","13","21","12","22","14", "41");
$required = array("1","2","11","41");
$disallowed = array("13","21","12","22","14");
if(getStatus($array,$required,$disallowed){
echo "All Valid";
}else{
echo "Some Inputs Are Invalid";
}
}