I am trying to convert the following code into a Ternary Operator, but it is not working and I am unsure why. I think my problem is that I do not know how to express the elseif
operation in ternary format. From my understanding and elseif
is performed the same way as an if
operation by using the format : (condition) ? 'result'
.
if ($i == 0) { $top = '<div class="active item">'; } elseif ($i % 5 == 0) { $top = '<div class="item">'; } else { $top = ''; } $top = ($i == 0) ? '<div class="active item">' : ($i % 5 == 0) ? '<div class="item">' : '';
$top = ($i == 0) ? '<div class="active item">' : (($i % 5 == 0) ? '<div class="item">' : '');
you need to add parenthesis' around the entire else block
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