+ 6
[Solved] Use case of "?" and ":" in PHP? (if-else)
Hello my dear friends. Please tell me what is the use case of "?" and ":" in this code: $color = "Green"; $color_default = "Blue"; $var=($color==$color_default)? 1:2; https://code.sololearn.com/wvguk8JOO93C/?ref=app
3 odpowiedzi
+ 4
Its a short form of If-else, called ternary operator.
If the condition is true then code after ? mark will be executed, else code after : mark will be executed..
edit: Siavash Kardar Tehran
ex:
$var=(true)? "if true part ":"else part";
echo $var; //output : " if true part"
$var=(false)? "true part": "else part";
echo $var; // output : "else part "
+ 6
Jayakrishna🇮🇳 Thank you. 🌹❤
+ 2
It's also called conditional statements it saves line of code at place of if else condition.