两个数组,已一个数组为key排序


<?php

function sort_arr($key, $arr){
        $ret =array();
        foreach($key as $value){
                if(!empty($arr[$value])){
                        $ret[$value] = $arr[$value];
                }
        }
        return $ret;
}

$key = array('c', 'a', 'b');
$arr = array('a' => array('aa'), 'c' => array('cc'), 'b' => array('bb'));

$sort = sort_arr($key, $arr);
var_dump($sort);

Jason.wang

When you find your talent can't afford to be ambitious, be quiet and study !

You may also like...