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,076 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.
My Site | Regular Expression Tester
busman posted this at 11:59 — 18th June 2009.
They have: 21 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
<?phpecho($result);
?>
Thanks
teammatt3 posted this at 14:36 — 18th June 2009.
He has: 2,076 posts
Joined: Sep 2003
<?php$test9 = ($b xor &b)? "true":"false";
?>
&b needs to be $b