- var_dump: documentation ( source)
- uasort: documentation ( source)
- strnatcasecmp: documentation ( source)
<?php declare(strict_types = 1);
final class Foo implements \Stringable {
private function __construct(public readonly string $value) {
}
public static function fromString(string $string): self {
return new self($string);
}
/**
* {@inheritdoc}
*/
public function __toString(): string {
return $this->value;
}
}
$options = [
Foo::fromString('c'),
Foo::fromString('b'),
Foo::fromString('a'),
Foo::fromString('ccc'),
Foo::fromString('bcc'),
];
uasort($options, strnatcasecmp(...));
var_dump($options);
var_dump(strnatcasecmp(Foo::fromString('c'), Foo::fromString('b')));