Is there a short way to write this? Like below:
<?php
$true=1;
$false=0;
$valid = array (
"part1" => $true,
"part2" => $true,
"part3" => $true
);
if($valid == $true){
echo "All the values are True!";
}else{
echo "At list one of the values is False";
}
?>
Instead of this:
<?php
if($valid['part1'] == $true && $valid['part2'] == $true && $valid['part3'] == $true{
echo "All the values are True!";
}else{
echo "At list one of the values is False";
}
?>
I have tried writing it as showed in the first example but it doesn't work
if (count(array_filter($valid)) == count($valid)) { echo 'All the values are Truthy'; } else { echo 'at least one of the values is falsey'; }array_filteris probably slower than thearray_uniqueanswer below.array_uniqueand equal it to 1 will make the code much faster and much less code is used in general