-1

我有一个php代码:

function display_categories_list($categories_list) {

    $display .= '<ul data-role="listview" data-theme="d" >';
    for($i=0; $i<count($categories_list); $i++) {
        $display .= '<li><a href="javascript:" class="displayStoresListByCategoryBtn" id="'.$categories_list[$i]['id'].'">';
        $display .= '<h3>'.$categories_list[$i]['name'].'</h3>';
        $display .= '<span class="ui-li-count"><font color="red"><small>'.$categories_list[$i]['nb'].'</small></font></span>';
        $display .= '</a></li>';
    }
    $display .= '</ul>';

    return $display;
}

我无法访问 sql 查询,我想用“名称字母 ASC”对我的结果进行排序。

我该怎么做?

4

1 回答 1

1
$categories_list[0]['name'] = "Bob";
$categories_list[0]['id'] = 1;
$categories_list[1]['name'] = "Carol";
$categories_list[1]['id'] = 2;
$categories_list[2]['name'] = "Ted";
$categories_list[2]['id'] = 3;
$categories_list[3]['name'] = "Alice";
$categories_list[3]['id'] = 4;

// Obtain a list of columns
foreach ($categories_list as $key => $row) {
    $tmp[$key]  = $row['name'];
}

array_multisort($tmp, SORT_ASC, $categories_list);

print_r($categories_list);

给出:

Array
(
    [0] => Array
        (
            [name] => Alice
            [id] => 4
        )

    [1] => Array
        (
            [name] => Bob
            [id] => 1
        )

    [2] => Array
        (
            [name] => Carol
            [id] => 2
        )

    [3] => Array
        (
            [name] => Ted
            [id] => 3
        )

)

http://php.net/manual/en/function.array-multisort.php

于 2012-10-07T16:37:30.597 回答