PHP vs ColdFusion/IF Statements

From Wikibooks, open books for an open world
Jump to navigation Jump to search

PHP IF STATEMENT

<?php

if( condition ){
// CODE TO EXECUTE

}

?>

The conditions are based on the information you want to compare.

So let's assume you want to compare apples to oranges, to see if they are the same.

if( "apples" == "oranges" ){
// OUTPUT ANSWER
echo "Apples = Oranges. True";
}

Now assume that you want to return an answer even if the conditions are not met. You would use what is called an else statement which looks as follows.

if( "apples" == "oranges" ){
// output

}
else
{
// output alternative
echo "Apples Do Not = Oranges";
}

ColdFusion is very different in its comparisons. They look as follows

<cfif apples eq oranges>

Apples = Oranges

</cfif>

If you notice that it's more of a <> based instead of a structure based. This can be an easier transition for HTML developers as it is tagged based

Now to return an alternate or else you do the almost exact same thing as in PHP, but it looks like this:

<cfif apples eq oranges>

Apples = Oranges

<cfelse>

Apples do not = oranges
</cfif>