Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

php - Troubleshooting "Unexpected T_ECHO" in ternary operator statement

($DAO->get_num_rows() == 1) ? echo("is") : echo("are");

This dose not seem to be working for me as intended, I get an error "Unexpected T_ECHO". I am expecting it to echo either 'is' or 'are'.

I have tried it without the brackets around the conditional. Am I just not able to use a ternary operator in this way?

The $DAO->get_num_rows() returns an integer value.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The Ternary operator is not identical to an if-then. You should have written it

echo ($DAO->get_num_rows() == 1) ? "is" : "are";

It returns the value in the 2nd or 3rd position. It does NOT execute the statement in the 2nd or 3rd position.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...