- Function Utf8_array_asort (& $array) {
- if (!isset ($array) | |!is_array ($array)) {
- return false;
- }
- foreach ($array as $k = = $v) {
- $array [$k] = iconv (' UTF-8 ', ' GB2312 ', $v);
- }
- Asort ($array);
- foreach ($array as $k = = $v) {
- $array [$k] = iconv (' GB2312 ', ' UTF-8 ', $v);
- }
- return true;
- }
Copy Code
Invocation Example:
- $ABC = Array (' A ' = ' guess ', ' b ' = = ' I ', ' c ' = ' Oh ', ' d ' = ' stick ', ' e ' + ' f ', ' f ' = = ' Dad ', ' z ' = ' state ');
- Utf8_array_asort ($ABC);
- Print_r ($ABC);
Copy Code
However, using this function to find that some of the text will be wrong, it may be that the UTF8 code does not recognize some words caused by "illegal characters", it is understood that the GBK character set is larger, replaced by GBK, plus ignore ignore the characters that do not know, change to the following
- Private Function Utf8_array_asort (& $array) {
- if (!isset ($array) | |!is_array ($array)) {
- return false;
- }
- foreach ($array as $k = = $v) {
- $array [$k] = iconv (' UTF-8 ', ' Gbk//ignore ', $v);
- }
- Asort ($array);
- foreach ($array as $k = = $v) {
- $array [$k] = iconv (' GBK ', ' Utf-8//ignore ', $v);
- }
- return true;
- }
Copy Code |