Skip to content

Latest commit

History

History
34 lines (27 loc) 路 1.13 KB

File metadata and controls

34 lines (27 loc) 路 1.13 KB

One way to compare strings in PHP is by using the strcmp() function. This is useful since not only can you determine if two strings are equal, but you can also test if one string is 'greater than' the other (using the corresponding ASCII values in each character comparison). What is the output of the following PHP script?

$test1聽=聽strcmp('hello',聽"hello");
$test2聽=聽strcmp("Hello",聽"hello");
$test3聽=聽strcmp('60',聽'500');

if聽($test1聽==聽0)聽聽聽聽聽{聽echo"a";聽}
elseif聽($test1聽<聽0)聽{聽echo"b";聽}
else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽{聽echo"c";聽}

if聽($test2聽==聽0)聽聽聽聽聽{聽echo"d";聽}
elseif聽($test2聽<聽0)聽{聽echo"e";聽}
else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽{聽echo"f";聽}

if聽($test3聽==聽0)聽聽聽聽聽{聽echo"g";聽}
elseif聽($test3聽<聽0)聽{聽echo"h";聽}
else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽{聽echo"i";聽}

Enter the exact script output

  • A) aei
  • B) a
  • C) iuo
  • D) bei
Answer

Answer: A