穩紮穩打-第一個技術部落格文章
<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>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了PHP 按二維數組的鍵值排序,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。