我想根据idai值对数组进行排序。我试过使用SORT,KSORT,USORT,但没有用。
这是我的数据
Array
(
[0] => Array
(
[0] => Array
(
[idai] => 4
[id] => 6187
[name] => xyz
)
[1] => Array
(
[idai] => 5
[id] => 5256
[name] => abc
)
[2] => Array
(
[idai] => 10
[id] => 21921
[name] => qwe
)
[3] => Array
(
[idai] => 6
[id] => 29679
[name] => IOU
)
[4] => Array
(
[idai] => 11
[id] => 21062
[name] => STU
)
)
)
而且我不确定为什么我会得到这个嵌套数组.. 这是我如何声明我的数组:
$return_arr = array();
$return_arr['feed'] = array();
我的代码将数据存储在我的数据库
中 $query = "SELECT * FROM user_post WHERE userid = '$friend_id'";
$result = mysql_query($query);
while( $row = mysql_fetch_array($result) ) {
$row_array['idai'] = $row['id'];
$row_array['id'] = $row['post_id'];
$row_array['name'] = $pic['name'];
array_push($return_arr['feed'],$row_array);
}
答案 0 :(得分:0)
试试这段代码:
$return_arr['feed'][$row['id']] = $row_array;
或者如果你不想嵌套数组:
$return_arr[$row['id']] = $row_array;
它将自动排序为数组键id