0

Can you explain to me the meaning of the following instruction :

? echo 2<=>1;

Indeed i do not understand how to interpret ? in the beginning.

Thank you

Amine
  • 17
  • 4
  • Does this answer your question? [Reference — What does this symbol mean in PHP?](https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – El_Vanja Nov 21 '20 at 21:43
  • no I can't find ? before the echo – Amine Nov 21 '20 at 21:47
  • It's there. It's part of a [ternary operator](https://stackoverflow.com/questions/1080247/what-are-the-php-operators-and-called-and-what-do-they-do). – El_Vanja Nov 21 '20 at 21:54
  • is not a ternary operator : (Condition) ? (Statement1) : (Statement2). Because i don't have any condition before ?. – Amine Nov 21 '20 at 21:59
  • Do you have anything on the previous line? Logic can be broken down into multiple lines. In fact, it is a common practice for ternaries. – El_Vanja Nov 21 '20 at 22:06
  • no nothing at all i only have this line on my whole .php file – Amine Nov 21 '20 at 22:09
  • That is not valid PHP. If you tried to run it, you'd get a syntax error. – El_Vanja Nov 21 '20 at 22:10
  • OK, thanks. it's the same thing i'm saying. I got it on a test on codinGame. but the possible answers are (-1, 0, 1, 2, true). – Amine Nov 21 '20 at 22:18
  • It's possible that somebody only copied part of it and forgot to delete the `?`. The question is obviously about `<=>`. – El_Vanja Nov 21 '20 at 22:20
  • It is a typo. Either developer has short tags enabled and cut off the ` – user3783243 Nov 21 '20 at 22:24
  • Yes possible. thank you – Amine Nov 21 '20 at 22:25

1 Answers1

1

This might be symbolizing a ternary logic statement. The '?' comes after the conditional statement followed by the "if" and "then" portion. In your case, (condition) ? 2<=>1; The '<=>' is known as a Spaceship Operator Documentation here. 2<=>1 evaluates to 1 since 2 is greater than one and it's on the left side. So your statement here will echo (or print to the console) "1" if the condition is true. Hoped this helped!!!

Ryan
  • 11
  • 3
  • what is the condition according to you. there is only this line on all my code. so I do not see the two points which are required in the syntax – Amine Nov 21 '20 at 22:11