Translating the question code for a ternary condition:
$total_gerente = (($total < 10)? 10: null);
Recommended to delimit the condition with parentheses to avoid problems with syntax errors.
Alternatively, you can 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 have no more than one line.
Example of code that generates error
($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 deepen more on the subject.
You can’t understand what you want. There’s nothing ternary about it. Explain it better. Explain calmly, think about the problem you want to solve. Try to give enough information to people who don’t know what you want to make them understand what you want.
– Maniero
In the ternary if you do not want the Else part, return/leave an empty string or null.
– rray
I don’t want the ELSE , but I don’t want to create the variable!
– Vagner Araujo
I can’t understand it yet, maybe putting more parts of the code in to give a better context would help. Or put it how you want it to be, even if in the wrong way.
– Maniero
You need the Else part to satisfy the syntax.
– rray
You really need to know more about your code, more than I can understand I believe what you want is
$total_gerente = $total < 10 ? 10 : $total;
, in that case the$total
is less than 10 assigns 10 in the variable$total_gerente
otherwise assigns the variable value$total
– abfurlan