稳扎稳打——第一个技术博文
<code><span>/** * 按二维数组的键值排序 *<span> @param</span> unknown $array 二维数组 *<span> @param</span> unknown $key 二维数组的键值 *<span> @param</span> string $order 升序/降序 *<span> @return</span> multitype:unknown 返回排序后的数组 */</span><span>public</span><span>static</span><span><span>function</span><span>arr_sort_in_key</span><span>(<span>$array</span>, <span>$key</span>, <span>$order</span> = <span>"asc"</span>)</span> {</span><span>$arr_nums</span> = <span>$arr</span> = <span>array</span>(); <span>foreach</span> (<span>$array</span><span>as</span><span>$k</span> => <span>$v</span>) { <span>$arr_nums</span>[<span>$k</span>] = <span>$v</span>[<span>$key</span>]; } <span>if</span>(<span>$order</span>==<span>'asc'</span>) { asort(<span>$arr_nums</span>); } <span>else</span> { arsort(<span>$arr_nums</span>); } <span>foreach</span>(<span>$arr_nums</span><span>as</span><span>$k</span>=><span>$v</span>) { <span>$arr</span>[] = <span>$array</span>[<span>$k</span>]; } <span>return</span><span>$arr</span>; } </code>
以上就介绍了PHP 按二维数组的键值排序,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。