note 114790 deleted from function.array-count-values by crell
| From: | crell@php.net | Date: | Tue, 12 Apr 2022 01:03:42 +0000 |
| Subject: | note 114790 deleted from function.array-count-values by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218178@lists.php.net to get a copy of this message | ||
Note Submitter: jakubplus at gmail dot com
----
In order to apply array_map with callback checking for localised values like city name, country
name, you have to provide some sort of comparison array.
Here's an example of array_count_values for Polish city names. Just switch array_keys /
array_values in order to obtain lowercase / uppercase.
$arr = array('Warsaw', 'Warsaw', 'WrocÅaw', 'PoznaÅ',
'KrakÃw', 'waRsaw', 'GdaÅsk', 'poznaÅ',
'WROCÅAW', 'kraków', 'GDAÅSK');
$lowertoupperpolish = array(
'Ä
' => 'Ä',
'Ä' => 'Ä',
'Ä' => 'Ä',
'Å' => 'Å',
'Å' => 'Å',
'ó' => 'Ã',
'Å' => 'Å',
'ż' => 'Ż',
'ź' => 'Ź',
);
function lowers($n) {
global $lowertoupperpolish;
return strtolower(str_replace(array_values($lowertoupperpolish),
array_keys($lowertoupperpolish), $n));
}
$result = array_count_values(array_map('lowers', $arr));
print_r($result); ...prints:
Array ( [warsaw] => 3 [wrocÅaw] => 2 [poznaÅ] => 2 [kraków] => 2 [gdaÅsk]
=> 2 )