{"id":749,"date":"2009-11-20T21:11:00","date_gmt":"2009-11-20T01:11:00","guid":{"rendered":""},"modified":"2013-11-26T14:33:41","modified_gmt":"2013-11-26T06:33:41","slug":"php%e6%95%b0%e7%bb%84%e6%8e%92%e5%ba%8f%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/749.html","title":{"rendered":"PHP\u6570\u7ec4\u6392\u5e8f\u51fd\u6570"},"content":{"rendered":"<p>\u5982\u679c\u4f60\u5df2\u7ecf\u4f7f\u7528\u4e86\u4e00\u6bb5\u65f6\u95f4PHP\u7684\u8bdd\uff0c\u90a3\u4e48\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u5bf9\u5b83\u7684\u6570\u7ec4\u6bd4\u8f83\u719f\u6089\u4e86\u2014\u2014\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u5141\u8bb8\u4f60\u5728\u5355\u4e2a\u53d8\u91cf\u4e2d\u5b58\u50a8\u591a\u4e2a\u503c\uff0c\u5e76\u4e14\u53ef\u4ee5\u628a\u5b83\u4eec\u4f5c\u4e3a\u4e00\u4e2a\u96c6\u5408\u8fdb\u884c\u64cd\u4f5c\u3002<br \/>\n\u7ecf\u5e38\uff0c\u5f00\u53d1\u4eba\u5458\u53d1\u73b0\u5728PHP\u4e2d\u4f7f\u7528\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u5bf9\u503c\u6216\u8005\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u975e\u5e38\u6709\u7528\u3002PHP\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9002\u5408\u591a\u79cd\u6570\u7ec4\u7684\u6392\u5e8f\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u5141\u8bb8\u4f60\u5728\u6570\u7ec4\u5185\u90e8\u5bf9\u5143\u7d20\u8fdb\u884c\u6392\u5217\uff0c\u4e5f\u5141\u8bb8\u7528\u5f88\u591a\u4e0d\u540c\u7684\u65b9\u6cd5\u5bf9\u5b83\u4eec\u8fdb\u884c\u91cd\u65b0\u6392\u5e8f\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u6211\u4eec\u5c06\u8ba8\u8bba\u8be5\u6392\u5e8f\u4e2d\u6700\u91cd\u8981\u7684\u51e0\u4e2a\u51fd\u6570\u3002<\/p>\n<p>\u7b80\u5355\u6392\u5e8f<\/p>\n<p>php\u6570\u7ec4\u6392\u5e8f\u51fd\u6570-php\u6570\u7ec4\u6392\u5e8f<br \/>\n\u9996\u5148\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u6700\u7b80\u5355\u7684\u60c5\u51b5\uff1a\u5c06\u4e00\u4e2a\u6570\u7ec4\u5143\u7d20\u4ece\u4f4e\u5230\u9ad8\u8fdb\u884c\u7b80\u5355\u6392\u5e8f\uff0c\u8fd9\u4e2a\u51fd\u6570\u65e2\u53ef\u4ee5\u6309\u6570\u5b57\u5927\u5c0f\u6392\u5217\u4e5f\u53ef\u4ee5\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u3002PHP\u7684sort\uff08\uff09\u51fd\u6570\u5b9e\u73b0\u4e86\u8fd9\u4e2a\u529f\u80fd\uff0c\u5982Listing A\u6240\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing A\r\n&lt;?php\r\n$data = array(5,8,1,7,2);\r\nsort($data);\r\nprint_r($data);\r\n?&gt;\r\n\r\n\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\u6240\u793a\uff1a\r\nArray (&#x5B;0] =&gt; 1\r\n&#x5B;1] =&gt; 2\r\n&#x5B;2] =&gt; 5\r\n&#x5B;3] =&gt; 7\r\n&#x5B;4] =&gt; 8\r\n)\r\n<\/pre>\n<p>\u4e5f\u80fd\u4f7f\u7528rsort\uff08\uff09\u51fd\u6570\u8fdb\u884c\u6392\u5e8f\uff0c\u5b83\u7684\u7ed3\u679c\u4e0e\u524d\u9762\u6240\u4f7f\u7528\u7684sort\uff08\uff09\u7b80\u5355\u6392\u5e8f\u7ed3\u679c\u76f8\u53cd\u3002Rsort\uff08\uff09\u51fd\u6570\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u4ece\u9ad8\u5230\u4f4e\u7684\u5012\u6392\uff0c\u540c\u6837\u53ef\u4ee5\u6309\u6570\u5b57\u5927\u5c0f\u6392\u5217\u4e5f\u53ef\u4ee5\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u3002Listing B\u7ed9\u6211\u4eec\u5c55\u793a\u4e86\u5b83\u7684\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing B\r\n&lt;?php $data = array(5,8,1,7,2);rsort($data); print_r($data);\r\n?&gt;\r\n\r\n\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a\r\nArray (&#x5B;0] =&gt; 8\r\n&#x5B;1] =&gt; 7\r\n&#x5B;2] =&gt; 5\r\n&#x5B;3] =&gt; 2\r\n&#x5B;4] =&gt; 1\r\n)\r\n<\/pre>\n<p>\u6839\u636e\u5173\u952e\u5b57\u6392\u5e8f<br \/>\n\u5f53\u6211\u4eec\u4f7f\u7528\u6570\u7ec4\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u6839\u636e\u5173\u952e\u5b57\u5bf9\u6570\u7ec4\u91cd\u65b0\u6392\u5e8f\uff0c\u4ece\u9ad8\u5230\u4f4e\u3002Ksort\uff08\uff09\u51fd\u6570\u5c31\u662f\u6839\u636e\u5173\u952e\u5b57\u8fdb\u884c\u6392\u5e8f\u7684\u51fd\u6570\uff0c\u540c\u65f6\uff0c\u5b83\u5728\u6392\u5e8f\u7684\u8fc7\u7a0b\u4e2d\u4f1a\u4fdd\u6301\u5173\u952e\u5b57\u7684\u76f8\u5173\u6027\u3002Listing C\u5c31\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing C\r\n&lt;?php $data = array(&quot;US&quot; =&gt; &quot;United States&quot;, &quot;IN&quot; =&gt; &quot;India&quot;, &quot;DE&quot; =&gt; &quot;Germany&quot;, &quot;ES&quot; =&gt; &quot;Spain&quot;);ksort($data); print_r($data);\r\n?&gt;\r\n\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a\r\nArray (&#x5B;DE] =&gt; Germany\r\n&#x5B;ES] =&gt; Spain\r\n&#x5B;IN] =&gt; India\r\n&#x5B;US] =&gt; United States\r\n)\r\n<\/pre>\n<p>Krsort\uff08\uff09\u51fd\u6570\u662f\u6839\u636e\u5173\u952e\u5b57\u5bf9\u6570\u7ec4\u8fdb\u884c\u5012\u6392\uff0cListing D\u5c31\u662f\u8fd9\u6837\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing D\r\n&lt;?php $data = array(&quot;US&quot; =&gt; &quot;United States&quot;, &quot;IN&quot; =&gt; &quot;India&quot;, &quot;DE&quot; =&gt; &quot;Germany&quot;, &quot;ES&quot; =&gt; &quot;Spain&quot;);krsort($data); print_r($data);\r\n?&gt;\r\n\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a\r\nArray (&#x5B;US] =&gt; United States\r\n&#x5B;IN] =&gt; India\r\n&#x5B;ES] =&gt; Spain\r\n&#x5B;DE] =&gt; Germany\r\n)\r\n<\/pre>\n<p>\u6839\u636e\u503c\u6392\u5e8f<br \/>\n\u5982\u679c\u4f60\u60f3\u4f7f\u7528\u503c\u6392\u5e8f\u6765\u53d6\u4ee3\u5173\u952e\u5b57\u6392\u5e8f\u7684\u8bdd\uff0cPHP\u4e5f\u80fd\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002\u4f60\u53ea\u8981\u4f7f\u7528asort\uff08\uff09\u51fd\u6570\u6765\u4ee3\u66ff\u5148\u524d\u63d0\u5230\u7684ksort\uff08\uff09\u51fd\u6570\u5c31\u53ef\u4ee5\u4e86\u3002\u5982Listing E\u6240\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing E\r\n&lt;?php $data = array(&quot;US&quot; =&gt; &quot;United States&quot;, &quot;IN&quot; =&gt; &quot;India&quot;, &quot;DE&quot; =&gt; &quot;Germany&quot;, &quot;ES&quot; =&gt; &quot;Spain&quot;);asort($data); print_r($data);\r\n?&gt;\r\n<\/pre>\n<p>\u4e0b\u9762\u5c31\u662f\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u3002\u8bf7\u6ce8\u610f\u8fd9\u4e2a\u7ed3\u679c\u4e0e\u4e0a\u9762\u4f7f\u7528ksort\uff08\uff09\u51fd\u6570\u6240\u5f97\u5230\u7684\u7ed3\u679c\u7684\u4e0d\u540c\u2014\u2014\u5728\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e2d\uff0c\u90fd\u662f\u6309\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u6392\u5e8f\u7684\uff0c\u4f46\u662f\u5b83\u4eec\u662f\u6839\u636e\u6570\u7ec4\u7684\u4e0d\u540c\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f\u7684\u3002<br \/>\n\u540c\u65f6\uff0c\u8bf7\u6ce8\u610f\u5173\u952e\u5b57-\u503c\u4e4b\u95f4\u7684\u8054\u7cfb\u4f1a\u59cb\u7ec8\u4fdd\u6301\uff1b\u5b83\u53ea\u662f\u5173\u952e\u5b57-\u503c\u5bf9\u6392\u5e8f\u540e\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u6392\u5e8f\u5e76\u4e0d\u4f1a\u6539\u53d8\u5b83\u4eec\u7684\u5bf9\u5e94\u5173\u7cfb\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nArray (&#x5B;DE] =&gt; Germany\r\n&#x5B;IN] =&gt; India\r\n&#x5B;ES] =&gt; Spain\r\n&#x5B;US] =&gt; United States\r\n)\r\n<\/pre>\n<p>\u73b0\u5728\uff0c\u4f60\u80af\u5b9a\u80fd\u731c\u5230\u8fd9\u79cd\u6392\u5e8f\u4e5f\u53ef\u4ee5\u8fdb\u884c\u5012\u6392\uff0c\u5b83\u4f7f\u7528arsort\uff08\uff09\u51fd\u6570\u5b8c\u6210\u8fd9\u4e2a\u529f\u80fd\u3002Listing F\u5c31\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing F\r\n&lt;?php $data = array(&quot;US&quot; =&gt; &quot;United States&quot;, &quot;IN&quot; =&gt; &quot;India&quot;, &quot;DE&quot; =&gt; &quot;Germany&quot;, &quot;ES&quot; =&gt; &quot;Spain&quot;);arsort($data); print_r($data);\r\n?&gt;\r\n<\/pre>\n<p>\u4e0b\u9762\u662f\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u6839\u636e\u503c\u6309\u5b57\u6bcd\u8868\u987a\u5e8f\u8fdb\u884c\u5012\u6392\u3002\u5c06\u4e0b\u9762\u7684\u7ed3\u679c\u4e0e\u7528krsort\uff08\uff09\u51fd\u6570\u8fdb\u884c\u5012\u6392\u540e\u751f\u6210\u7684\u7ed3\u679c\u8fdb\u884c\u6bd4\u8f83\uff0c\u5c31\u80fd\u5f88\u5bb9\u6613\u660e\u767d\u4e24\u8005\u7684\u4e0d\u540c\u4e86\u3002<\/p>\n<p>Array ([US] =&gt; United States<br \/>\n[ES] =&gt; Spain<br \/>\n[IN] =&gt; India<br \/>\n[DE] =&gt; Germany<br \/>\n)<\/p>\n<p>\u81ea\u7136\u8bed\u8a00\u6392\u5e8f<br \/>\nPHP\u6709\u4e00\u4e2a\u975e\u5e38\u72ec\u7279\u7684\u6392\u5e8f\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u7528\u8ba4\u77e5\u800c\u4e0d\u662f\u4f7f\u7528\u8ba1\u7b97\u89c4\u5219\u3002\u8fd9\u79cd\u7279\u6027\u79f0\u4e3a\u81ea\u7136\u8bed\u8a00\u6392\u5e8f\uff0c\u5f53\u521b\u5efa\u6a21\u7cca\u903b\u8f91\u5e94\u7528\u8f6f\u4ef6\u7684\u65f6\u5019\u8fd9\u79cd\u6392\u5e8f\u65b9\u5f0f\u975e\u5e38\u6709\u7528\u3002\u4e0b\u9762\u5927\u5bb6\u53ef\u4ee5\u6765\u770b\u770b\u5b83\u7684\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\uff0c\u5982Listing G\u6240\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing G\r\n&lt;?php $data = array(&quot;book-1&quot;, &quot;book-10&quot;, &quot;book-100&quot;, &quot;book-5&quot;); sort($data);print_r($data);\r\nnatsort($data); print_r($data);?&gt;\r\n\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a\r\nArray (&#x5B;0] =&gt; book-1\r\n&#x5B;1] =&gt; book-10\r\n&#x5B;2] =&gt; book-100\r\n&#x5B;3] =&gt; book-5\r\n)\r\nArray\r\n(\r\n&#x5B;0] =&gt; book-1\r\n&#x5B;3] =&gt; book-5\r\n&#x5B;1] =&gt; book-10\r\n&#x5B;2] =&gt; book-100\r\n)\r\n<\/pre>\n<p>\u5b83\u4eec\u7684\u4e0d\u540c\u5df2\u7ecf\u5f88\u6e05\u695a\u4e86\uff1a\u7b2c\u4e8c\u4e2a\u6392\u5e8f\u7ed3\u679c\u66f4\u76f4\u89c2\uff0c\u66f4\u201c\u4eba\u6027\u5316\u201d\uff0c\u7136\u800c\u7b2c\u4e00\u4e2a\u5219\u66f4\u7b26\u5408\u7b97\u6cd5\u89c4\u5219\uff0c\u66f4\u5177\u201c\u8ba1\u7b97\u673a\u201d\u7279\u70b9\u3002<br \/>\n\u81ea\u7136\u8bed\u8a00\u80fd\u8fdb\u884c\u5012\u6392\u5417\uff1f\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff01\u53ea\u8981\u5bf9natsort\uff08\uff09\u7684\u7ed3\u679c\u4f7f\u7528array_reverse()\u51fd\u6570\u5c31\u53ef\u4ee5\u4e86\uff0cListing H\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing H\r\n&lt;?php $data = array(&quot;book-1&quot;, &quot;book-10&quot;, &quot;book-100&quot;, &quot;book-5&quot;);natsort($data); print_r(array_reverse($data));\r\n?&gt;\r\n\u4e0b\u9762\u662f\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\uff1a\r\nArray (&#x5B;0] =&gt; book-100\r\n&#x5B;1] =&gt; book-10\r\n&#x5B;2] =&gt; book-5\r\n&#x5B;3] =&gt; book-1\r\n)\r\n<\/pre>\n<p>\u6839\u636e\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u89c4\u5219\u6392\u5e8f<br \/>\nPHP\u4e5f\u80fd\u8ba9\u4f60\u5b9a\u4e49\u81ea\u5df1\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4f60\u81ea\u5df1\u7684\u6bd4\u8f83\u51fd\u6570\uff0c\u5e76\u628a\u5b83\u4f20\u9012\u7ed9usort\uff08\uff09\u51fd\u6570\u3002\u5982\u679c\u7b2c\u4e00\u4e2a\u53c2\u6570\u6bd4\u7b2c\u4e8c\u4e2a\u53c2\u6570\u201c\u5c0f\u201d\u7684\u8bdd\uff0c\u6bd4\u8f83\u51fd\u6570\u5fc5\u987b\u8fd4\u56de\u4e00\u4e2a\u6bd40\u5c0f\u7684\u6570\uff0c\u5982\u679c\u7b2c\u4e00\u53c2\u6570\u6bd4\u7b2c\u4e8c\u4e2a\u53c2\u6570\u201c\u5927\u201d\u7684\u8bdd\uff0c\u6bd4\u8f83\u51fd\u6570\u5e94\u8be5\u8fd4\u56de\u4e00\u4e2a\u6bd40\u5927\u7684\u6570\u3002<br \/>\nListing I\u5c31\u662f\u8fd9\u6837\u7684\u4e00\u4e2a\u4f8b\u5b50\uff0c\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u6839\u636e\u5b83\u4eec\u7684\u957f\u5ea6\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff0c\u6700\u77ed\u7684\u9879\u653e\u5728\u6700\u524d\u9762\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing I\r\n&lt;?php $data = array(&quot;joe@host.com&quot;, &quot;john.doe@gh.co.uk&quot;, &quot;asmithsonian@us.info&quot;, &quot;jay@zoo.tw&quot;);usort($data, \u2018sortByLen\u2019);\r\nprint_r($data); function sortByLen($a, $b) {\r\nif (strlen($a) == strlen($b)) {\r\nreturn 0;\r\n} else {\r\nreturn (strlen($a) &gt; strlen($b)) ? 1 : -1;\r\n}\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u6837\uff0c\u5c31\u521b\u5efa\u4e86\u6211\u4eec\u81ea\u5df1\u7684\u6bd4\u8f83\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u4f7f\u7528strlen\uff08\uff09\u51fd\u6570\u6bd4\u8f83\u6bcf\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u4e2a\u6570\uff0c\u7136\u540e\u5206\u522b\u8fd4\u56de1\uff0c0\u6216-1.\u8fd9\u4e2a\u8fd4\u56de\u503c\u662f\u51b3\u5b9a\u5143\u7d20\u6392\u5217\u7684\u57fa\u7840\u3002\u4e0b\u9762\u662f\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nArray (&#x5B;0] =&gt; jay@zoo.tw\r\n&#x5B;1] =&gt; joe@host.com\r\n&#x5B;2] =&gt; john.doe@gh.co.uk\r\n&#x5B;3] =&gt; asmithsonian@us.info\r\n)\r\n<\/pre>\n<p>\u591a\u7ef4\u6392\u5e8f<br \/>\n\u6700\u540e\uff0cPHP\u4e5f\u5141\u8bb8\u5728\u591a\u7ef4\u6570\u7ec4\u4e0a\u6267\u884c\u4e00\u4e9b\u6bd4\u8f83\u590d\u6742\u7684\u6392\u5e8f\u2014\u2014\u4f8b\u5982\uff0c\u9996\u5148\u5bf9\u4e00\u4e2a\u5d4c\u5957\u6570\u7ec4\u4f7f\u7528\u4e00\u4e2a\u666e\u901a\u7684\u5173\u952e\u5b57\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u518d\u6839\u636e\u53e6\u4e00\u4e2a\u5173\u952e\u5b57\u8fdb\u884c\u6392\u5e8f\u3002\u8fd9\u4e0e\u4f7f\u7528SQL\u7684ORDER BY\u8bed\u53e5\u5bf9\u591a\u4e2a\u5b57\u6bb5\u8fdb\u884c\u6392\u5e8f\u975e\u5e38\u76f8\u4f3c\u3002\u4e3a\u4e86\u80fd\u66f4\u597d\u7684\u660e\u767d\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u8bf7\u4ed4\u7ec6\u770bListing J\u6240\u4e3e\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nListing J\r\n&lt;?php $data = array(array(&quot;id&quot; =&gt; 1, &quot;name&quot; =&gt; &quot;Boney M&quot;, &quot;rating&quot; =&gt; 3),\r\narray(&quot;id&quot; =&gt; 2, &quot;name&quot; =&gt; &quot;Take That&quot;, &quot;rating&quot; =&gt; 1),\r\narray(&quot;id&quot; =&gt; 3, &quot;name&quot; =&gt; &quot;The Killers&quot;, &quot;rating&quot; =&gt; 4),\r\narray(&quot;id&quot; =&gt; 4, &quot;name&quot; =&gt; &quot;Lusain&quot;, &quot;rating&quot; =&gt; 3),\r\n); foreach ($data as $key =&gt; $value) {\r\n$name&#x5B;$key] = $value&#x5B;'name'];\r\n$rating&#x5B;$key] = $value&#x5B;'rating'];\r\n}\r\narray_multisort($rating, $name, $data); print_r($data);?&gt;\r\n<\/pre>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u5728$data\u6570\u7ec4\u4e2d\u6a21\u62df\u4e86\u4e00\u4e2a\u884c\u548c\u5217\u6570\u7ec4\u3002\u7136\u540e\uff0c\u6211\u4f7f\u7528array_multisort()\u51fd\u6570\u5bf9\u6570\u636e\u96c6\u5408\u8fdb\u884c\u91cd\u6392\uff0c\u9996\u5148\u662f\u6839\u636erating\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\uff0c\u5982\u679crating\u76f8\u7b49\u7684\u8bdd\uff0c\u518d\u6839\u636ename\u6392\u5e8f\u3002\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nArray (&#x5B;0] =&gt; Array\r\n(\r\n&#x5B;id] =&gt; 2\r\n&#x5B;name] =&gt; Take That\r\n&#x5B;rating] =&gt; 1\r\n) &#x5B;1] =&gt; Array\r\n(\r\n&#x5B;id] =&gt; 1\r\n&#x5B;name] =&gt; Boney M\r\n&#x5B;rating] =&gt; 3\r\n)\r\n&#x5B;2] =&gt; Array\r\n(\r\n&#x5B;id] =&gt; 4\r\n&#x5B;name] =&gt; Lusain\r\n&#x5B;rating] =&gt; 3\r\n)\r\n&#x5B;3] =&gt; Array\r\n(\r\n&#x5B;id] =&gt; 3\r\n&#x5B;name] =&gt; The Killers\r\n&#x5B;rating] =&gt; 4\r\n)\r\n)\r\n<\/pre>\n<p>array_multisort()\u51fd\u6570\u662fPHP\u4e2d\u6700\u6709\u7528\u7684\u51fd\u6570\u4e4b\u4e00\uff0c\u5b83\u6709\u975e\u5e38\u5e7f\u6cdb\u7684\u5e94\u7528\u8303\u56f4\u3002\u53e6\u5916\uff0c\u5c31\u5982\u4f60\u5728\u4f8b\u5b50\u4e2d\u6240\u770b\u5230\u7684\uff0c\u5b83\u80fd\u5bf9\u591a\u4e2a\u4e0d\u76f8\u5173\u7684\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u4e0b\u6b21\u6392\u5e8f\u7684\u57fa\u7840\uff0c\u8fd8\u53ef\u4ee5\u5bf9\u6570\u636e\u5e93\u7ed3\u679c\u96c6\u8fdb\u884c\u6392\u5e8f\u3002<br \/>\n\u8fd9\u4e9b\u4f8b\u5b50\u5e94\u8be5\u8ba9\u4f60\u5bf9PHP\u4e2d\u5404\u79cd\u6570\u7ec4\u6392\u5e8f\u51fd\u6570\u7684\u4f7f\u7528\u6709\u4e86\u521d\u6b65\u7684\u4e86\u89e3\uff0c\u4e5f\u5411\u4f60\u5c55\u793a\u4e86\u4e00\u4e9b\u9690\u85cf\u5728PHP\u6570\u7ec4\u5904\u7406\u5de5\u5177\u5305\u7684\u5185\u90e8\u529f\u80fd\u3002<br \/>\n\u6700\u540e\uff0c\u795d\u4f60\u80fd\u6109\u5feb\u7684\u4f7f\u7528\u8fd9\u4e9b\u529f\u80fd\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u5df2\u7ecf\u4f7f\u7528\u4e86\u4e00\u6bb5\u65f6\u95f4PHP\u7684\u8bdd\uff0c\u90a3\u4e48\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u5bf9\u5b83\u7684\u6570\u7ec4\u6bd4\u8f83\u719f\u6089\u4e86\u2014\u2014\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u5141\u8bb8\u4f60\u5728\u5355\u4e2a\u53d8\u91cf\u4e2d\u5b58\u50a8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=749"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":5254,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/749\/revisions\/5254"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}