것은

2011-09-28 3 views
0

, 다음과 같은 출력을 얻기위한 어떤 PHP 함수가 자사의 'Z- 색인'키 값것은

$array = array('the-1'=> array('name'=>'lorem','pos'=>array('top'=>'90','left'=>'80'),'zindex'=>2), 
     'the-2'=> array('name'=>'ipsum','pos'=>array('top'=>'190','left'=>'180'),'zindex'=>1), 
     'the-3'=> array('name'=>'lorem ipsum','pos'=>array('top'=>'20','left'=>'30'),'zindex'=>3) 
     ) 

로 PHP 배열에 따라 정렬하는 방법

$array = array(
     'the-2'=> array('name'=>'ipsum','pos'=>array('top'=>'190','left'=>'180'),'zindex'=>1), 
     'the-1'=> array('name'=>'lorem','pos'=>array('top'=>'90','left'=>'80'),'zindex'=>2), 
     'the-3'=> array('name'=>'lorem ipsum','pos'=>array('top'=>'20','left'=>'30'),'zindex'=>3) 
     ) 

답변

0
usort($array,function($el1,$el2){ 
    return $el1-$el2; 
}); 

이 필요 PHP5.3

당신이 이전 버전의 '지원은 익명 함수를 교체해야하는 경우 보통 하나의

2
usort($array, function($a, $b) { 
    if ($a['name'] == $b['name']) { 
     return 0; 
    } 
    return ($a['name'] < $b['name']) ? -1 : 1; 
}); 

에 의해이 당신을 위해 트릭을 할해야 ... 그것은 나를 위해 한)