In PHP, the problem of Chinese sort failure is handled by using Asort,
PHP has a very convenient way to reorder the array of--asort, about the use of Asort can be seen here. However, when sorting an array containing Chinese keys, Asort sometimes does not follow the alphabetical order. This is mainly a coding problem, if encoded as UTF-8, it will not be sorted alphabetically, the solution is first converted to GBK encoding, sorted and then back to UTF-8.
Example: There is an array of $pass, similar in structure to
Array ([0] = StdClass Object ( [Username] = Zhang San [Password] = dq9uqqw2+uudoszpqmnyvgg9l+ rhzb6lrzbvdvael9uobnf2ztwunykhzfjhbzch+lrsslrx9esqu/n3gslsua== ) [1] = = StdClass Object ( [username ] = John Doe [Password] = 2p/3j50ibk1bymjhl+7/tt0d6luoqmn9m8klxjczbcajqth5749jftth17wxibz9p425b4kiv/xdv/ 7bu4pjaq== ) [2] = = StdClass Object ( [username] = Harry [Password] = caq8lq0l6uxjprx+ scbsbfuojsf+ox98gwo6c/aquxq/y/aj/l/ziegsxrsv+olck7ikojj4izzvx8dmpwzrra== ) [3] = = StdClass Object ( [Username] = Zhao Liu [Password] = taxp4jx0vo3voflyanfgrsjzy76wqqhmnzyan9cyi20ukxlfmscxrfr3p525eimy0pg5zk8btbjos/rymxzjgq== ) )
Using the following code, the array will be sorted according to the username pinyin.
foreach ($pass as $key) {$key->username = iconv (' UTF-8 ', ' GBK ', $key->username);} Asort ($pass), foreach ($pass as $key) {$key->username = iconv (' GBK ', ' UTF-8 ', $key->username);}
http://www.bkjia.com/PHPjc/865619.html www.bkjia.com true http://www.bkjia.com/PHPjc/865619.html techarticle PHP in the use of Asort for Chinese sorting failure problem processing, PHP has a very convenient way to reorder the array--asort, about the use of Asort can be seen here. But ... ..