2012-05-16 87 views
0

我有這個說法有些問題,PHP if/else語句的問題

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

+1

也許不關你的if語句由於執行壞邏輯是什麼?你甚至試圖調試它? –

+0

你的意見是什麼? 'var_dump($ vehicle)' –

+1

你確定在'beginnig'中設置了$ vehicle ['make']'嗎? – Hindol

回答

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"; 
} 
1

簡單一些:

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

謝謝!這是有效的,現在更清潔。 –