1

この行を使用して、2 次元配列を名前フィールドに基づいて昇順に並べ替えています。

 array_multisort($contact[0]['name'],SORT_DESC,$contact[0]['image'],$contact[0]['url'],$contact[0]['catimg'],$contact[0]['count']);

ただし、正しくソートされない場合があります。

何が悪いの?

ありがとう

4

2 に答える 2

0

作業に使用する場合は、データの列を作成する必要がありますarray_multisort。概要は次のようになります。

$names = array();
$images = array();
$urls = array();
// ... add more as needed
// make rows of data for sorting
foreach ($contact as $contact_row) {
    $names[]  = $contact_row['name'];
    $images[] = $contact_row['image'];
    $urls[]   = $contact_row['url'];
    // ... add more as needed
}
array_multisort($names, SORT_DESC, $images, $urls, $contact); // the last one is the array you want to sort

var_export($contact); // at this point this should be ordered
于 2012-08-14T12:20:53.697 に答える
0

関数に渡される引数は配列ではないようです。

usortを使用してみてください:

usort($contact, function($a, $b){
    return strcmp($a['name'], $b['name']);
});
于 2012-08-14T12:21:13.707 に答える