0

I'm having some issues with this statement,

<?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>

Any suggestions? currently it just displays $cert_mess as 'make' and ignores the if / else if statements.

4
  • 1
    Probably none of your if statements execute due to bad logic? Have you even tried to debug it? Commented May 16, 2012 at 1:26
  • What is your input? var_dump($vehicle) Commented May 16, 2012 at 1:28
  • 1
    Are you sure $vehicle['make'] is set in the beginnig? Commented May 16, 2012 at 1:30
  • Actually I just figured it out - did a var_dump and "certified" was correct not "Certified". Thanks for the help! Any recommendations to make this code a little cleaner/simpler? Commented May 16, 2012 at 1:44

2 Answers 2

1

A simpler code can be the following:

$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";
}
Sign up to request clarification or add additional context in comments.

Comments

1

Simpler still:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.