0

我对这个声明有一些问题,

<?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 语句。

4

2 回答 2

1

更简单的代码如下:

$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";
}
于 2012-05-16T01:48:36.603 回答
1

更简单:

$cert_mess = $vehicle['make'];
if (!in_array($vehicle['make'], array('Cadillac', 'Honda')) || $vehicle['certified'] == '0')
{
    $cert_mess = 'DFWCertAutos';
}
于 2012-05-16T01:53:39.833 回答