Is there a possibility to create a simpler if ternary, say without the else block code? how would it look?
Type:
if($total < 10){
$total_gerente = 10;
}
For what I know the ternary has IF and ELSE. Is it possible to only have the if block?
Is there a possibility to create a simpler if ternary, say without the else block code? how would it look?
Type:
if($total < 10){
$total_gerente = 10;
}
For what I know the ternary has IF and ELSE. Is it possible to only have the if block?
Translating the question code into a ternary condition:
$total_gerente = (($total < 10)? 10: null);
Recommended to delimit the condition with parentheses to avoid problems with syntax errors.
Alternatively, you could do so if you did not want to set a specific value in the opposite condition
($total < 10)? $total_gerente = 10: null;
Note:
You should be aware that actions should not have more than one line.
Error code example
($total < 10)? $total_gerente = 10; $outra_var = 'foo': null;
When there is such a need you can use techniques with anonymous functions, but as this is not part of the question, I abstain and go deeper into the subject.
You can make it simpler in some ways: 1st
if($total < 10) $total_gerente = 10;
2nd
if($total < 10) :
$total_gerente = 10;
endif;
3rd
if($total < 10)
$total_gerente = 10;
I hope I have helped.