18 lines
433 B
PHP
18 lines
433 B
PHP
|
<?php
|
||
|
function unique_chars(string $input, bool $multibyte = true): int {
|
||
|
$chars = [];
|
||
|
$strlen = $multibyte ? 'mb_strlen' : 'strlen';
|
||
|
$substr = $multibyte ? 'mb_substr' : 'substr';
|
||
|
$length = $strlen($input);
|
||
|
|
||
|
for($i = 0; $i < $length; $i++) {
|
||
|
$current = $substr($input, $i, 1);
|
||
|
|
||
|
if(!in_array($current, $chars, true)) {
|
||
|
$chars[] = $current;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return count($chars);
|
||
|
}
|