この行を使用して、2 次元配列を名前フィールドに基づいて昇順に並べ替えています。
array_multisort($contact[0]['name'],SORT_DESC,$contact[0]['image'],$contact[0]['url'],$contact[0]['catimg'],$contact[0]['count']);
ただし、正しくソートされない場合があります。
何が悪いの?
ありがとう
作業に使用する場合は、データの列を作成する必要があります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
関数に渡される引数は配列ではないようです。
usortを使用してみてください:
usort($contact, function($a, $b){
return strcmp($a['name'], $b['name']);
});