Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
echo (true?'true':'t'); //it's wrong......why???
Posted
Comments
Prerak Patel 25-Oct-11 4:57am    
Who said it's wrong? What problem you get?
dctplink 25-Oct-11 5:05am    
I add this to demo.php
then it show this "PHP Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /home/lingdecong/php_project/demo.php on line 21
". And the line 21 is echo (true?'true':'t');.
dctplink 25-Oct-11 7:10am    
I am sorry for my carelessness......so sorry

This should evaluate to 'true' of course.
 
Share this answer
 
It should (and does) print the string "true".
If you expect it to do otherwise, then you need to look at the PHP ternary operator[^] in more detail.
 
Share this answer
 
The error message in your comment suggests that the line before the echo is missing a semi-colon (;) at the end of it.

The ; is not optional in PHP.
 
Share this answer
 
Comments
dctplink 25-Oct-11 7:09am    
I am sorry for my carelessness......so sorry

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900