「php入門」array_multisortで多次元の配列をソートする

//配列
$students = array(
array(‘name’ => ‘山田’, ‘age’ => 30)
, array(‘name’ => ‘杉村’, ‘age’ =>26)
, array(‘name’ => ‘山城’, ‘age’ =>23)
, array(‘name’ => ‘上村’, ‘age’ =>22)
);

$ages = array();
foreach ($students as $user) {
$ages[] = $user[‘age’];
}
array_multisort($ages, SORT_ASC, $students);

Comments are closed.