View Single Post
Old 11-18-2009, 08:14 AM   #2 (permalink)
maeltar
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

Hello and welcome, the answer is easier than you think...

1 = True
(NULL) = False

Try changing the numbers you will see you still get 1 or NULL

Which means the variable $less will be 1 or nothing at all



Hope that clears it up for you

Examples...

Code:
<?php
$a = 10;
$b = 20;

// Check $a less than $b
$less = ($a < $b);

// If $a is not equal to 1 (TRUE), show a message
if ($less != 1)
        {
        echo "NULL\n";
        // we need to exit to program
        exit();
        }

echo $less . "  TRUE\n";

?>
swapping the numbers round would normally produce nothing for the "echo" statement to write so for an example you could use another boolean operative to display a message if the answer is NULL..

Code:
<?php
$a = 20;
$b = 10;

// Check $a less than $b
$less = ($a < $b);

// If $a is not equal to 1 (TRUE), show a message
if ($less != 1)
        {
        echo "NULL\n";
        // we need to exit to program
        exit();
        }

echo $less . "  TRUE\n";

?>
This snippet would echo "NULL" as the statement
Code:
if ($less != 1)
is true, as $a "is not equal to" 1


P.S.

I have changed $one to $a and $two to $b

I don't believe it's a codeing practice thing, but it's the way I was taught, not to use written numbers as variables as it makes the code harder to read in a way, if you use a similar format to algebra type equations you automatically (sic) can read it easier. (I know I can)
__________________
Thanks... Simon

Sex, Drugs & Linux Rules

Last edited by maeltar : 11-18-2009 at 08:37 AM. Reason: Added examples
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote