0

The first part before || works on a standalone basis, but the second added (OR) second condition doesn't perform.

eg. $category="Cycle", or ($category) Cycle is not ($primaryName) Running I would expect to echo Running;

eg $category="Surf" echo nothing;

eg $category="Tech" and $primaryName="Tech" echo nothing;

eg $category="Tech" and &primaryName="Clean" echo "Clean";

What am I doing wrong here?

<?php $categorycheck = array("Surf", "Sail", "Driving", "Flying");

if ((! in_array($category, $categorycheck)) || ($category != $primaryName))
{
    echo '<li>' . $primaryName . '</li>';
}
?>
2
  • 2
    It looks like you need AND instead of OR inside your if statement. Commented Feb 5, 2014 at 21:10
  • 2 times -if not- and -or or and- or got me confused. Need a coffee! Thanks Mutale! Commented Feb 5, 2014 at 21:16

2 Answers 2

2

Replace || with &&, otherwise it will evaluate as true every time $category is not an element of $categorycheck.

Sign up to request clarification or add additional context in comments.

Comments

2

thanks to Mutale, the working code is:

<?php $categorycheck = array("Surf", "Sail", "Driving", "Flying");

if ((! in_array($category, $categorycheck)) && ($category != $primaryName))
{
echo '<li>' . $primaryName . '</li>';
}
?>

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.