Php Objective Questions with Answers for written test exams 24

Question 24
Which of the following output ‘True’?

A. if(“true”) { print “True”; }

B. $string = “true”;

if($string == 0) { print “True”; }

C. $string = “true”;

if(strncasecmp($string, “Trudeau”, 4)) { print “True”; }

D. if(strpos(“truelove”, “true”)) { print “True”; }

E. if(strstr(“truelove”, “true”)) { print “True”; }
Answers 24


Answers A, B, C, and E are correct. Answer A is correct because a non-empty

string will evaluate to true inside an if() block. Answer B is covered in the chapter—

when comparing a string and an integer with ==, PHP will convert the string

into an integer. ‘true’ converts to 0, as it has no numeric parts. In answer C,

strncasecmp() returns 1 because the first four characters of ‘Trud’ come before

the first four characters of true when sorted not case sensitively. Answer D is

incorrect because strpos() returns 0 here (true matches truelove at offset 0).

We could make this return True by requiring strpos() to be !== false. Answer

E is correct because strstr() will return the entire string, which will evaluate to

true in the if() block.

  







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 ---