note 114790 added to function.array-count-values

From: Date: Mon, 07 Apr 2014 11:36:19 +0000
Subject: note 114790 added to function.array-count-values
Groups: php.notes 
Request: Send a blank email to php-notes+get-199205@lists.php.net to get a copy of this message
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 ) ---- Server IP: 46.17.113.2 Probable Submitter: 178.36.216.83 ---- Manual Page -- http://php.net/manual/en/function.array-count-values.php Edit -- https://master.php.net/note/edit/114790 Del: integrated -- https://master.php.net/note/delete/114790/integrated Del: useless -- https://master.php.net/note/delete/114790/useless Del: bad code -- https://master.php.net/note/delete/114790/bad+code Del: spam -- https://master.php.net/note/delete/114790/spam Del: non-english -- https://master.php.net/note/delete/114790/non-english Del: in docs -- https://master.php.net/note/delete/114790/in+docs Del: other reasons-- https://master.php.net/note/delete/114790 Reject -- https://master.php.net/note/reject/114790 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199205) next »