note 114790 deleted from function.array-count-values by crell

From: 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 )

« previous php.notes (#218178) next »