Possible Duplicate:
What is the PHP ? : operator called and what does it do?
i was interviewed with a very basic question of PHP which was like:
echo ('True' ? (true ? 't' : 'f') : 'False');
Can Someone explain the details of the output it will yield?
Thanks
This will echo t.
Because of first it will check the first condition that will give true. and after that in next condition it again give true and execute the first condition that is t.
In if and else condition it will be write as follow:
if('True') { //condition true and go to in this block
if(true){ //condition true and go to in this block
echo 't'; // echo t
} else {
echo 'f';
}
} else {
echo 'False';
}
Looking at this version should make it clear:
if('True'){ // evaluates true
if(true){ // evaluates tre
echo 't'; // is echo'd
}else{
echo 'f';
}
}else {
echo 'False';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With