Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 usort 对数组进行排序,但它不起作用,我做错了什么?
$tmp = array(); $tmp[] = array( 'x' => 0.000123 ); $tmp[] = array( 'x' => 0.000120 ); $tmp[] = array( 'x' => 0.000333 ); usort($tmp, function ($a, $b) { return $b['x'] - $a['x']; }); print_r($tmp);
$tmp = array(); $tmp[] = array( 'x' => 0.000123 ); $tmp[] = array( 'x' => 0.000120 ); $tmp[] = array( 'x' => 0.000333 ); usort($tmp, function ($a, $b) { $a = $a['x']; $b = $b['x']; if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; });
试试这个