I want to use continue keyword in ternary operator for code simplification. I am trying to following way and found an syntax error.
in_array($SqlPackageCategoryProductResultRowObj->product_id, $individualProduct)?continue:"";
How can i use it.
The ternary operator takes 3 expressions in the form of (expr1) ? (expr2) : (expr3)
.
continue
is a control structure statement, not an expression. And hence, it can't be an operand of the ternary operator. In fact, none of PHP's operators accept control structures as operands, as far as I'm aware. The same applies to the rest of the broad C-family languages as well.
And for the sake of readability, it is probably better to use an if
statement in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With