Next Sep 17 PreviousItem 547208
Consider the following code:
<?php
$res = strcmp("a", "b");
?>
What will be the value of $res
.
A: true
B: false
C: -1
D:
E: 1
Answer
If you ever thought: 'strange: strcmp("equal", "equal")
returns false
' here's why. strcmp()
returns a value that is very much in line with what usort()
needs: -1
if the first argument should sort before the second, 1
if it should sort after and
if the are equal. So the correct answers is C.
Also note PHP naming inconsistency:
strcmp
str_replace
substr
substr_compare
substr_replace
li>
PHP has a rich set of string functions but unfortunately there is not much logic in their names. Well you'll say, who cares, we've got code completion and PHP code looks like battle ground anyway. Be warned: there's no code completion at the exam, you've got to learn these inconsequent naming schemes by heart.