Comparing and Sorting Strings

=== compares bytes. == and < compare numerically when both sides are numeric strings, so '1e3' == '1000' (Subsection 4.2.4). strcmp() compares bytes and returns a negative number, 0 or a positive one (-1 or 1 since PHP 8.2); strcasecmp() ignores ASCII case, strncmp() compares a prefix, and strnatcmp() puts img10 after img2, as sort($a, SORT_NATURAL) does for arrays.

Byte, natural and locale-aware ordering (compare.php)PHP
<?php
echo json_encode(['1e3' == '1000', '10' < '9', '10' < '9a']), ' ', strcmp('apple', 'banana'),
    ' ', strcasecmp('PHP', 'php'), ' ', strncmp('order-17', 'order-99', 6), ' ',
    strnatcmp('img12', 'img10'), "\n";
$names = ['Zoë', 'zebra', 'Émile', 'Eve', 'Ångström', 'Adam'];
sort($names);
echo implode(' ', $names), "\n";
foreach (['fr_FR', 'sv_SE'] as $locale) {
    (new Collator($locale))->sort($names);
    echo "$locale: ", implode(' ', $names), "\n";
}
echo levenshtein('recieve', 'receive'), ' ', similar_text('World', 'Word'), ' ',
    soundex('Robert'), ' ', soundex('Rupert'), "\n";
Output
[true,false,true] -1 0 0 1
Adam Eve Zoë zebra Ångström Émile
fr_FR: Adam Ångström Émile Eve zebra Zoë
sv_SE: Adam Émile Eve zebra Zoë Ångström
2 4 R163 R163

Byte order puts accented capitals after z. The intl Collator sorts as readers expect, by language: French files Å with A, Swedish after Z. For "did you mean", levenshtein() counts edits and soundex() gives Robert and Rupert one key. Compare secret tokens with hash_equals() (Subsection 4.17.11).