Home > front end >  Multiple condition and expression with a ternary in php
Multiple condition and expression with a ternary in php

Time:10-01

if(!$customLength){
?>
<th class="sku-label-value download-url-construct <?=$columnClassParent ?>">
 <span 
    data-option-id="<?=$values['option_id']?>"
    id="ns_code_<?= ((stripos($title, 'i.p. rating') !== false) ? 'iprating' : $title) ?>"
    data-code-sku="<?=$dataCodeSku ?>">
<?=$values['sku'] ?></span>
</th>
<?php
}

I want to have another ternary condition on the ID is that possible?

So for this line

    id="ns_code_<?= ((stripos($title, 'i.p. rating') !== false) ? 'iprating' : $title) ?>"

I would want to be able to account for another word also and still account for the ip rating. I hope that makes sense.

CodePudding user response:

If you want to account for another word instead of 'i.p. rating' in the title, you can have another ternary in the "else" part:

    id="ns_code_<?= ((stripos($title, 'i.p. rating') !== false) ? 'iprating' : ((stripos($title, 'whatever') !== false) ? 'whatever' : $title)) ?>"

At this point, I would suggest switching back to a standard condition block for a better readability.

  • Related