PHP声明的时间到期

The listings on my site have three states: - Active - Sold - Expired

I wrote this to get listings that are in Active or Sold to automatically expire if they pass a certain date.

<span class="detail">Status: <?php 
    if(strtotime($property['data']['field_3211']) < time()){ echo 'Expired'; }
    else if($property['raw']['field_3022'] == 5) echo 'Active';
    else if($property['raw']['field_3022'] == 8 ) echo 'Sold'; 
    else echo 'Not set';
    ?>
</span>

I now want to change it to only expire if the status is set to active and ignore the expiry if it is set to sold.

All you need to do is specify in the if that outputs the Expired message that the record must be active as well as < time().

<span class="detail">Status: 
<?php 
    if(strtotime($property['data']['field_3211']) < time() &&
        $property['raw']['field_3022'] == 5) 
    { 
        echo 'Expired'; 
    }
    else if($property['raw']['field_3022'] == 5) {
        echo 'Active';
    }
    else if($property['raw']['field_3022'] == 8 ) {
        echo 'Sold'; 
    }
    else {
        echo 'Not set';
    }
?>
</span>

Try this:

<span class="detail">Status: <?php
    $status  = $property['raw']['field_3022'];
    $expired = ( strtotime($property['data']['field_3211']) < time() );

    switch (true) {
        case ($status == 5) : echo ($expired) ? 'Expired' : 'Active'; break;
        case ($status == 8) : echo 'Sold'; break;
        default             : echo 'Not set';
    }
?>
</span>