PHP if/else 语句问题


PHP if/else statement issue

我对这个陈述有一些问题,

<?php 
    $cert_mess = $vehicle['make'];
    if ($vehicle["make"] == "Honda" && $vehicle["Certified"] == "0")  {
        $cert_mess = "DFWCertAutos";
    }
    elseif ($vehicle["make"] == "Cadillac" && $vehicle["Certified"] == "0") {
        $cert_mess = "DFWCertAutos";
    }
    elseif (!in_array($vehicle['make'], array('Cadillac','Honda') )) {
        $cert_mess = "DFWCertAutos";
    }
?>
<div style="font-size:10px; padding:10px; padding-top: 0px;">*This car is <?php 
echo $cert_mess ?> certified.</div>

有什么建议吗? 目前它只是将$cert_mess显示为"make",并忽略 if/else if 语句。

更简单的代码可以是:

$cert_mess = $vehicle['make'];
if (($vehicle["make"] == "Honda" && $vehicle["Certified"] == "0")
    || ($vehicle["make"] == "Cadillac" && $vehicle["Certified"] == "0")
    || !in_array($vehicle['make'], array('Cadillac','Honda'))
) {
    $cert_mess = "DFWCertAutos";
}

更简单:

$cert_mess = $vehicle['make'];
if (!in_array($vehicle['make'], array('Cadillac', 'Honda')) || $vehicle['certified'] == '0')
{
    $cert_mess = 'DFWCertAutos';
}