Jump to content

Archived

This topic is now archived and is closed to further replies.

breadnbutter

AND/OR

Recommended Posts

I'm pretty new to PHP. I have done a few pages of code, and I'm now starting to get my head round it. However, I've looked on php.net and can't find the right syntax for an 'AND' or and 'OR' statement, a bit like in SQL. Is there such a thing?

Here is the context I want to use it in.

$areab = ($_POST['county']);

if ($areab == "Cambridgeshire")
{echo "E Anglia";} else {echo "";}

This is going to be part of a much more complex bit of code, but |I am using the echo to test to see if this state ment works. Which is does. But what I want to do is

$areab = ($_POST['county']);

if ($areab == ("Cambridgeshire") OR ("Suffolk") OR ("Norfolk")
{echo "E Anglia";} else {echo "";}

but this doesn't work, what is it that I should be doing?

Share this post


Link to post
Share on other sites
well just for future reference, it would look like this:

if (($areab == "Cambridgeshire" OR ($areab=="Suffolk") OR ($areab=="Norfolk"))
{echo "E Anglia";} else {echo "";}

you can also use || instead of OR

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.