Would assigning an if statements condition to a variable , then using that variable in the if statement be bad practice?
I just thought about this and tested:
<?php
$c1 = 3;
$test1 = (isset($c1) && $c1 >2);
if($test1){
echo 'true';
}
else {
echo 'false';
}
Which actually works and does return true
without any errors.
But even though it works, I want to make sure this isn't frowned upon.
The reason why I tried this, is because I'm creating a web app with over 8 dynamic filter options. Each of these options affect the others. This will allow me to cut down my code size and make it much neater.
For example:
Filter 1: Date range
Filter 2: Call Status (Answered/ Busy/ etc...)
Filter 3: Client Phone number
So if my user selects a date range, all filters will refresh and must only display the options that would be relevant in that range. (This I have working)
What are your thoughts on assigning a condition to a variable?
Aucun commentaire:
Enregistrer un commentaire