I want to add some cases to what Sbastian wrote some years ago, and cumulated with other user that says the comparison is case insensitive (php 4).
Tested on PHP 7.4 -> 8.4
You can see that PHP 8 will vanish integer 1 from result if there are a boolean true value when the flag is SORT_REGULAR.
<?php declare(strict_types=1); // it works the same without it
$a = [true, false, 'true', 'false', 1, null, '', '0', '123', 0, 123, 'AaA', 'AAA'];
foreach (['SORT_REGULAR', 'SORT_NUMERIC', 'SORT_STRING', 'SORT_LOCALE_STRING'] as $flag) {
$unique = array_unique($a, constant($flag));
$acc = '';
foreach ($unique as $k => $u) {
$type = gettype($u);
$formattedVal = is_bool($u) ? ($u ? 'true' : 'false') : (is_string($u) ? "'$u'" : $u);
$acc .= "$type(" . $formattedVal . ') | ';
}
echo "{$flag} ==> " . trim($acc, ' | ') . PHP_EOL;
}
// PHP 7.4
// SORT_REGULAR ==> boolean(true) | boolean(false) | integer(1) | string('123') | integer(0)
// SORT_NUMERIC ==> boolean(true) | boolean(false) | string('123')
// SORT_STRING ==> boolean(true) | boolean(false) | string('true') | string('false') | string('0') | string('123') | string('AaA') | string('AAA')
// SORT_LOCALE_STRING ==> boolean(true) | boolean(false) | string('true') | string('false') | string('0') | string('123') | string('AaA') | string('AAA')
// PHP 8 -> 8.4
// SORT_REGULAR ==> boolean(true) | boolean(false)
// SORT_NUMERIC ==> boolean(true) | boolean(false) | string('123')
// SORT_STRING ==> boolean(true) | boolean(false) | string('true') | string('false') | string('0') | string('123') | string('AaA') | string('AAA')
// SORT_LOCALE_STRING ==> boolean(true) | boolean(false) | string('true') | string('false') | string('0') | string('123') | string('AaA') | string('AAA')
?>