Php Objective Questions with Answers for written test exams 62

Question 62
Suppose that you are receiving input from the user in the form of the string

“0mydeviceid” for a field for which you only allow valid numeric values.You

want to test if this variable is equal to 0 and, if it isn’t, output an error.Which

comparison operation should you use?

A. (0 = “0mydeviceid”)

B. (0 == “0mydeviceid”)

C. (0 === “0mydeviceid”)

D. None of the above
Answers 62


Answer D is correct. Because PHP is automatically trying to convert the string

“0mydeviceid” to 0 when comparing it with the equal operator == , your condition

in answer B evaluates to true even though the user input is not a valid numeric

value.The expression in answer C, on the other hand, correctly determines that

the user input is not a valid integer—but that will always be the case because

you’re likely to always receive user input in the form of a string—so, even if that

string can be converted to an integer value, the identity test will fail.

  







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---