php - How to sort 1 value in array to top? -


for example:

$array = ("1", "2", "3", "4", "5"); 

now want sort number 3 on top, result:

$array = ("3", "1", "2", "4", "5"); 

if want sort array except one, try :

function cmptotop($a, $b){     if($a === '3') return -1; //change comparison value     if($b === '3') return 1; //change comparison value     if($a === $b) return 0;     return ($a < $b) ? -1 : 1; }  $a = array('3', '2', '5', '6', '3', '1');  cmptotop($a, "cmp"); //result : array('3', '3', '1', '2', '5', '6') 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -