I'm trying to sort an array first by it's values and then by it's keys but php is not doing well with Persian characters.
Persian alphabets are similar to Arabic alphabets except some additional characters like 'گ چ پ ژ ک' and PHP is doing great at sorting Arabic letters in Persian Alphabets but the rest is not in their order.
For example
$str = 'ا ب پ ت ث ج چ ح خ د ذ ر ز ژ ص ض ط ظ ع غ ف ق ک گ ل م ن و ه ی';
$arr = explode(' ', $str);
will create an array ($arr
) containing all Persian alphabets in correct alphabetical order. and if I shuffle it and use asort
function like following:
shuffle($arr);
asort($arr);
var_dump($arr);
it will end as something like this:
array
2 => string 'ا'
1 => string 'ب'
22 => string 'ت'
29 => string 'ث'
20 => string 'ج'
12 => string 'ح'
21 => string 'خ'
18 => string 'د'
6 => string 'ذ'
3 => string 'ر'
27 => string 'ز'
17 => string 'ص'
11 => string 'ض'
25 => string 'ط'
5 => string 'ظ'
16 => string 'ع'
8 => string 'غ'
26 => string 'ف'
14 => string 'ق'
9 => string 'ل'
0 => string 'م'
7 => string 'ن'
10 => string 'ه'
28 => string 'و'
24 => string 'پ'
23 => string 'چ'
13 => string 'ژ'
19 => string 'ک'
4 => string 'گ'
15 => string 'ی'
which is wrong!
24th item should be after 1st, 23rd should be after 20 and so on.
How can I write a functions doing something similar to PHP's own sorting functions? Or maybe there's a way to make PHP functions work for persian characters?