0
0
PHPprogramming~20 mins

String comparison functions in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of strcmp with different cases
What is the output of this PHP code snippet?
PHP
<?php
$str1 = "Hello";
$str2 = "hello";
$result = strcmp($str1, $str2);
echo $result;
?>
A0
B1
C-32
DSyntaxError
Attempts:
2 left
💡 Hint
strcmp compares strings byte by byte and is case-sensitive.
Predict Output
intermediate
2:00remaining
Output of strcasecmp with different cases
What will this PHP code output?
PHP
<?php
$str1 = "World";
$str2 = "world";
$result = strcasecmp($str1, $str2);
echo $result;
?>
A0
B-1
CWarning: Undefined function
D1
Attempts:
2 left
💡 Hint
strcasecmp compares strings ignoring case differences.
Predict Output
advanced
2:00remaining
Behavior of strncmp with partial string comparison
What is the output of this PHP code?
PHP
<?php
$str1 = "apple";
$str2 = "apples";
$result = strncmp($str1, $str2, 5);
echo $result;
?>
A-1
B0
C1
DFatal error
Attempts:
2 left
💡 Hint
strncmp compares only the first n characters of two strings.
Predict Output
advanced
2:00remaining
Output of substr_compare with offset and length
What does this PHP code output?
PHP
<?php
$str1 = "abcabc";
$str2 = "xyzabc";
$result = substr_compare($str1, $str2, 3, 3);
echo $result;
?>
AWarning: Wrong parameters
B0
C23
D-23
Attempts:
2 left
💡 Hint
substr_compare compares substrings starting at offset for given length.
🧠 Conceptual
expert
2:00remaining
Which function is best for case-insensitive string comparison with offset?
You want to compare two strings ignoring case, starting at a specific position and for a specific length. Which PHP function should you use?
Astrncasecmp
Bstrncmp
Csubstr_compare
Dstrcasecmp
Attempts:
2 left
💡 Hint
Look for a function that combines case-insensitive, length-limited, and offset-based comparison.