Search code examples
phparrayssortingsql-order-byletter

PHP sort array using specific letter


I have an php array like below:

Array ( 
[0] => Array ( [value] => 5 [label] => Akon )
[1] => Array ( [value] => 6 [label] => Angel ) 
[2] => Array ( [value] => 7 [label] => Britny ) 
[3] => Array ( [value] => 9 [label] => Mark Anthony ) 
[4] => Array ( [value] => 8 [label] => Michel ) 
[5] => Array ( [value] => 4 [label] => Shaggy ) 
[6] => Array ( [value] => 3 [label] => Smith ) 
) 

I need this array sort by specific letter. For example, if I sort by this "M" letter array should look like below.

Array ( 
[3] => Array ( [value] => 9 [label] => Mark Anthony ) 
[4] => Array ( [value] => 8 [label] => Michel ) 
[6] => Array ( [value] => 3 [label] => Smith ) 
[0] => Array ( [value] => 5 [label] => Akon ) 
[1] => Array ( [value] => 6 [label] => Angel ) 
[2] => Array ( [value] => 7 [label] => Britny ) 
[5] => Array ( [value] => 4 [label] => Shaggy ) 
) 

The begging letter should comes to first of array.(here begin with m) I greatly appreciated your any kind of help. Thank you very much...


Solution

  • this is an example i found on php.net that could help you and maintain the index : http://www.php.net/manual/en/function.sort.php#99419