[UPHPU] A little if-then help...

Mac Newbold mac at macnewbold.com
Fri Apr 23 18:08:14 MDT 2004


Today at 5:23pm, Ashley Oviatt said:

>foreach($_POST as $k=>$textfield1)
>	{
>	if ($k == "Phone_Number" or "Cell_Phone")
>		{
>		do some pdflib stuff
>		}
>	}
>
>So I just want the "do some pdflib stuff" to happen if $k ==
>"Phone_Number" or "Cell_Phone" . If it equals anything else, just
>continue on in the foreach until it finishes.

>What really happens, though, is that it prints all of the $POST data
>onto the form. If I leave out the or, ie if ($k == "Phone_Number") ,
>then it works as I'd expect it to.

What you've got written there will make the condition true if either
$k=="Phone_Number", or if "Cell_Phone" is true, and "Cell_Phone" is a
string that is always true.

I think this may be what you're looking for:

if ($k == "Phone_Number" || $k == "Cell_Phone")

You can use either "OR" operator ("or"/"||") in this case. They both mean
the same thing, but the || has higher precedence. In particular, if you
have an assignment of some variety (=, +=, etc), the || will bind tighter
than the assignment, and the "or" will not:

$a = 0 || 1;

will set $a to 0 and evaluate to 1, but

$a = 0 or 1;

will set $a to 1 and evaluate to 1.

Is that right? Can someone confirm that?

Mac

--
Mac Newbold		MNE - Mac Newbold Enterprises, LLC
mac at macnewbold.com	http://www.macnewbold.com/



More information about the UPHPU mailing list