MIKESTOWE.COM

you are here

Weekly PHP Test

What does the following code echo out:

PHP
1
2
3
4
5
if('ORANGE' > 'apple') {
echo 'orange';
} else {
echo 'apple';
}

ANSWER:

1
apple

The values are converted based on the ASCII alphabet, in which uppercase letters come before lowercase letters, and thus are assigned a lower value than the lowercase letters. This means that the word ‘apple’ is assigned a higher value than the word ‘ORANGE’ because of the case-sensitivity, making ‘apple’ greater than ‘ORANGE.’ When we change ‘ORANGE’ to lowercase, the otherwise same code would return ‘orange.’

Share this Page:
Facebook Twitter Linkedin Reddit Tumblr Email

Leave a Reply

Your email address will not be published. Required fields are marked *