Example 1 — Check If Two Strings Are Equal
A result of 0 means the strings match exactly.
<?php
if (strcmp("apple", "apple") === 0) {
echo "Strings are equal", PHP_EOL;
} How It Works
- Pass two strings. Both are
"apple". - Compare byte by byte. Every byte matches.
- Get 0. That is the code for equal.
- Test with === 0. A strict check is the safe habit.

