Both methods of determination are correct and good. Another way to do this: ternary operator .
Here you override the assigned variable with a different "y" depending on $var_two
$var_one = 'x'; if ($var_two) $var_one = 'y';
Use complete if / else. Here you simply assign the value $var_one depending on $var_two .
if ($var_two) $var_one = 'y'; else $var_one = 'x';
As I said, you can do this with the ternary operator , see example, override . existing variable.
$var_one = x; $var_one = ($var_two) ? 'y' : $var_one;
again, assignment with new values.
$var_one = ($var_two) ? 'y' : 'x';
Note. . It depends on the code that I need to compare with each other, there are two types, one is assignment, the other is redefinition, I should prefer the ternary operator , if less complexity, or straight forward if.....else .
Franene konok
source share