Testing Operands
Please could you tell me why this is not echo(ing) on to my page?
<?php
$a = true;
$b = false;
#test both operands for true (&& = and)
$test1 = ($a && $a)? "true","false";
$test2 = ($a && $b)? "true","false";
$test3 = ($b && $b)? "true","false";
#test either operand for TRUE (|| = or)
$test4 = ($a || $a)? "true","false";
$test5 = ($a || $b)? "true","false";
$test6 = ($b || $b)? "true","false";
#test for single operand is TRUE
$test7 = ($a xor $a)? "true","false";
$test8 = ($a xor $b)? "true","false";
$test9 = ($b xor &b)? "true","false";
#invert values ( ! = NOT )
$test10 = ( !$a )? "true","false";
$test11 = ( !$b )? "true","false";
$result = "AND Operand - 1:$test1 2:$test2 3:$test3<br/><br/>";
$result .= "OR Operand - 1:$test4 2:$test5 3:$test6<br/><br/>";
$result .= "XOR Operand - 1:$test7 2:$test8 3:$test9<br/><br/>";
$result .= "NOT Operand - 1:$test10 2:$test11";
?>
Untitled Document
<?php
echo($result);
?>
teammatt3 posted this at 23:31 — 17th June 2009.
He has: 2,102 posts
Joined: Sep 2003
You're testing with the ternary operator. Its syntax is:
(condition) ? (true event) : (false event)
It looks like you're using a comma instead of a colon in your code.
busman posted this at 11:59 — 18th June 2009.
They have: 20 posts
Joined: Dec 2008
I have uploaded the changes to the code and still it will not echo?
<?php
$a = true;
$b = false;
#test both operands for true (&& = and)
$test1 = ($a and $a)? "true":"false";
$test2 = ($a and $b)? "true":"false";
$test3 = ($b and $b)? "true":"false";
#test either operand for TRUE (|| = or)
$test4 = ($a or $a)? "true":"false";
$test5 = ($a or $b)? "true":"false";
$test6 = ($b or $b)? "true":"false";
#test for single operand is TRUE
$test7 = ($a xor $a)? "true":"false";
$test8 = ($a xor $b)? "true":"false";
$test9 = ($b xor &b)? "true":"false";
#invert values ( ! = NOT )
$test10 = ( !$a )? "true":"false";
$test11 = ( !$b )? "true":"false";
$result = "AND Operand - 1:$test1 2:$test2 3:$test3<br/><br/>";
$result .= "OR Operand - 1:$test4 2:$test5 3:$test6<br/><br/>";
$result .= "XOR Operand - 1:$test7 2:$test8 3:$test9<br/><br/>";
$result .= "NOT Operand - 1:$test10 2:$test11";
?>
Untitled Document
<?php
echo($result);
?>
Thanks
teammatt3 posted this at 14:36 — 18th June 2009.
He has: 2,102 posts
Joined: Sep 2003
<?php
$test9 = ($b xor &b)? "true":"false";
?>
&b needs to be $b
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.