开发者

sorting an array between array and string values

I am creating a template parser and i need to sort the array of variables that gets passed into the parser so that each array element that IS an array get processed first. For example:

$data = array(
    'name' => 'Steven',
    'type' => array(
        'gender' => 'M',
        'age' => 23'
    )
)
开发者_如何学JAVA

I need 'type' to be first since it is an array, and 'name' to be last. Does anyone have an idea on how to do this? Ive looked at php.net's manual at the different sort functions, but dont see how any apply to my situation.


function cmp($a, $b) {
    return is_array($a) ? -1 : 1;
}    
uasort($data, "cmp");

This will sort the array based on the value type...alphabetically. Array comes before String.


function cmp($a, $b) {
   return is_array($a)? -1 : 0;
}

uasort($data, "cmp");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜