{"id":747,"date":"2009-11-20T11:33:00","date_gmt":"2009-11-20T03:33:00","guid":{"rendered":""},"modified":"2013-11-26T14:43:18","modified_gmt":"2013-11-26T06:43:18","slug":"php%e6%95%b0%e7%bb%84%e5%ba%94%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/747.html","title":{"rendered":"PHP\u6570\u7ec4\u5e94\u7528\u6559\u7a0b"},"content":{"rendered":"<p>1\uff0c\u6570\u7ec4\u7684\u5b9a\u4e49\u548c\u521d\u59cb\u5316<\/p>\n<p>\u4ec0\u4e48\u662f\u6570\u7ec4\uff1f\u6570\u7ec4\u662f\u4e00\u79cd\u7f16\u7a0b\u7ed3\u6784\uff0c\u5b83\u662f\u4e00\u4e2a\u5b58\u50a8\u4e00\u7ec4\u6216\u4e00\u7cfb\u5217\u6570\u503c\u7684\u53d8\u91cf\u3002<br \/>\n\u6bd4\u5982\u4eba\u53e3\u666e\u67e5\u65f6\u5bf9\u4e2a\u4eba\u7684\u8eab\u4efd\u767b\u8bb0\uff0c\u5982\u59d3\u540d\u3001\u6027\u522b\u3001\u6c11\u65cf\u3001\u51fa\u751f\u7b49\u5c31\u53ef\u4f5c\u4e3a\u6570\u7ec4\u3002<br \/>\nPHP\u4e2d\u521b\u5efa\u6570\u7ec4\u4f7f\u7528array()\u7ed3\u6784\u6765\u5b9a\u4e49\uff0c\u6bd4\u5982\uff1a<\/p>\n<p>$people=array(\u2018name\u2019,&#8217;sex\u2019,&#8217;nation\u2019,&#8217;brith\u2019);<\/p>\n<p>\u800c\u5982\u4f55\u663e\u793a\u6570\u7ec4\u4e2d\u7684\u5404\u5143\u7d20\u7684\u503c\uff0c\u6211\u4eec\u5219\u662f\u4f7f\u7528\u4ece0\u5f00\u59cb\u7684\u7d22\u5f15\uff0c\u7d22\u5f15\u53f7\u5728\u53d8\u91cf\u540d\u79f0\u540e\u7684\u65b9\u62ec\u53f7\u4e2d\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$people=array(\u2018name\u2019,'sex\u2019,'nation\u2019,'birth\u2019);\r\necho $people&#x5B;2];\r\n?&gt;\r\n<\/pre>\n<p>\u8f93\u51fa\u7684$people[2]\u5c31\u662f\u663e\u793a\u7684\u662fnation\uff08\u7d22\u5f15\u7b2c\u4e00\u9879\u4ece0\u8ba1\u6570\uff09\u3002<br \/>\nPHP\u9664\u4e86\u652f\u6301\u6570\u5b57\u7d22\u5f15\u6570\u7ec4\u4ee5\u5916\uff0c\u8fd8\u652f\u6301\u76f8\u5173\u6570\u7ec4\u3002\u6240\u8c13\u76f8\u5173\u6570\u7ec4\uff0c\u5c31\u662f\u53ef\u81ea\u5b9a\u4e49\u5173\u952e\u5b57\u6765\u66ff\u6362\u4e0d\u76f4\u89c2\u7684\u6570\u5b57\u7d22\u5f15\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$peoples=array(\u2018xm\u2019=&gt;\u2019name\u2019,'xb\u2019=&gt;\u2019sex\u2019,'mz\u2019=&gt;\u2019nation\u2019,'cs\u2019=&gt;\u2019birth\u2019);\r\necho $peoples&#x5B;'cs'];\r\n?&gt;\r\n<\/pre>\n<p>\u4f7f\u7528\u76f8\u5173\u6570\u7ec4\u4f7f\u5f97\u8f93\u51fa\u7684\u9009\u62e9\u5f88\u76f4\u89c2\uff08\u4e0d\u9700\u8981\u9884\u5148\u8ba1\u7b97\u7d22\u5f15\u53f7\u7136\u540e\u8f93\u51fa\uff09\uff0c\u5b9a\u4e49\u7684\u5173\u952e\u5b57\u548c\u503c\u4e4b\u95f4\u4f7f\u7528\u201c=&gt;\u201d\u7b26\u53f7\u5b9a\u4e49\u3002<br \/>\n\u6839\u636ePHP\u6570\u7ec4\u5143\u7d20\u7684\u4e24\u79cd\u663e\u793a\u65b9\u5f0f\uff0c\u8fd8\u53ef\u4ee5\u5982\u53d8\u91cf\u4e00\u6837\u65e0\u9700array()\u58f0\u660e\u548c\u521d\u59cb\u5316\uff0c\u76f4\u63a5\u81ea\u52a8\u521b\u5efa\u6570\u5b57\u3002\u6bd4\u5982<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$people&#x5B;0]=\u2019name\u2019;\r\n$people&#x5B;1]=\u2019sex\u2019;\r\n$people&#x5B;2]=\u2019nation\u2019;\r\n$people&#x5B;3]=\u2019brith\u2019;\r\n\u6216\u8005\r\n$peoples&#x5B;'xm']=\u2019name\u2019;\r\n$peoples&#x5B;'xb']=\u2019sex\u2019;\r\n$peoples&#x5B;'mz']=\u2019nation\u2019;\r\n$peoples&#x5B;'cs']=\u2019birth\u2019;\r\n<\/pre>\n<p>\u8be5\u6570\u7ec4\u7684\u5927\u5c0f\u6839\u636e\u6240\u589e\u52a0\u5143\u7d20\u7684\u591a\u5c11\u52a8\u6001\u7684\u53d8\u5316\u3002<\/p>\n<p>2\uff0c\u6570\u7ec4\u5143\u7d20\u7684\u663e\u793a<br \/>\n\u5728\u5982\u4e0a\u4f7f\u7528\u7684\u65e0\u8bba$people[2]\u4e5f\u597d\uff0c\u65e0\u8bba$peoples[&#8216;cs&#8217;]\u4e5f\u597d\uff0c\u90fd\u53ea\u662f\u8f93\u51fa\u5df2\u77e5\u7684\u660e\u786e\u4f4d\u7f6e\u7684\u6570\u7ec4\u5143\u7d20\u503c\uff0c\u5982\u4f55\u5feb\u901f\u8f93\u51fa\u6240\u6709\u6216\u90e8\u5206\u7684\u6570\u7ec4\u5143\u7d20\uff0c\u4f7f\u7528\u5faa\u73af\u8bed\u53e5\u65e0\u7591\u662f\u6700\u5feb\u7684\u65b9\u6cd5\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$people=array(\u2018name\u2019,'sex\u2019,'nation\u2019,'birth\u2019);\r\nfor ($i=0;$i&lt;4;$i++)\r\n     echo &quot;$people&#x5B;$i] &quot;;\r\n?&gt;\r\n<\/pre>\n<p>\u9664\u4e86\u4f7f\u7528\u4e86\u89e3\u5faa\u73af\u6b21\u6570\u7684for\u5faa\u73af\u4ee5\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5bf9\u5faa\u73af\u6b21\u6570\u65e0\u987b\u8981\u6c42\u7684foreach\u8bed\u53e5\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$people=array(\u2018name\u2019,'sex\u2019,'nation\u2019,'birth\u2019);\r\nforeach($people as $xiangmu)\r\n     echo $xiangmu;\r\n?&gt;\r\n<\/pre>\n<p>$xiangmu\u53d8\u91cf\u5c06\u4fdd\u5b58\u6570\u7ec4\u4e2d\u7684\u5404\u5143\u7d20\u503c\uff0c\u4f9d\u6b21\u663e\u793a\u51fa\u6765\u3002\u5f53\u7136\uff0c\u4e3a\u4e86\u8f93\u51fa\u7684\u6570\u636e\u80fd\u95f4\u9694\u533a\u5206\uff0c\u53ef\u5728\u6570\u7ec4\u5143\u7d20\u4e4b\u540e\u8f93\u51fa\u7a7a\u683c\uff1a<br \/>\necho $xiangmu.&#8221; &#8220;;<br \/>\n\u5047\u5982\u60a8\u6709\u5f88\u5927\u7684\u4e00\u4e2a\u6570\u7ec4\uff0c\u800c\u6240\u8981\u5b8c\u6210\u7684\u4ec5\u662f\u627e\u51fa\u4e00\u4e2a\u5b58\u5728\u7684\u7ed9\u5b9a\u503c\uff0c\u60a8\u80fd\u591f\u4f7f\u7528in_array()\u4ee5\u8fd4\u56detrue \u6216 false\u3002\u5982\u4e0b\u4ee3\u7801\u5c06\u8f93\u51fa\u201cNot found in this array\u201d\u2015\u2015\u56e0\u4e3a\u60a8\u5c06\u5728$namesArray\u4e2d\u5bfb\u627e\u4e00\u4e2a\u5e76\u4e0d\u5b58\u5728\u7684\u201cAlber \u201d\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? $namesArray = array(&quot;Joe&quot;, &quot;Jane&quot;, &quot;Bob&quot;, &quot;Mary&quot;, &quot;Paul&quot;, &quot;Eddie&quot;, &quot;John&quot;);\r\n$lookingFor = &quot;Albert&quot;;\r\nif (in_array($lookingFor, $namesArray)) {\r\necho &quot;You\u2019ve found it!&quot;;\r\n} else {\r\necho &quot;Not found in this array!&quot;;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u5047\u5982\u60a8\u6539\u53d8\u4e86$lookingFor\u7684\u503c\uff0c\u5c06\u5176\u53d8\u4e3a\u201cMary\u201d\uff0c\u60a8\u5c06\u5f97\u5230\u6d88\u606f\u201cYou\u2019ve found it!\u201d\u2015\u2015\u56e0\u4e3a\u201cMary\u201d\u662f$namesArray\u7684\u4e00\u90e8\u5206\u3002<br \/>\n\u5047\u5982\u5e0c\u671b\u5bf9\u6570\u7ec4\u5143\u7d20\u8ba1\u6570\uff0c\u60a8\u80fd\u591f\u4f7f\u7528count()\u51fd\u6570\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? $namesArray = array(&quot;Joe&quot;, &quot;Jane&quot;, &quot;Bob&quot;, &quot;Mary&quot;, &quot;Paul&quot;, &quot;Eddie&quot;, &quot;John&quot;);\r\n$count = count($namesArray); ?&gt;\r\n<\/pre>\n<p>$count\u503c\u5c06\u4e3a7\u3002<br \/>\n\u60a8\u80fd\u591f\u5bf9\u4efb\u4f55\u6570\u7ec4\u6dfb\u52a0\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5728\u5df2\u5b58\u5728\u6570\u7ec4\u7684\u5f00\u59cb\u6216\u672b\u5c3e\u3002\u60a8\u4e5f\u80fd\u591f\u4f7f\u7528\u51fd\u6570\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u6216\u591a\u4e2a\u6570\u7ec4\u5143\u7d20\u7684\u65b0\u6570\u7ec4\u3002\u5408\u5e76\u65f6\u6bcf\u4e2a\u6570\u7ec4\u5c06\u6309\u9700\u8981\u7684\u987a\u5e8f\u6392\u5217\u3002\u5047\u5982\u60a8\u7684\u6570\u7ec4\u5df2\u6709\u5185\u90e8\u7684\u6392\u5e8f\uff0c\u60a8\u9700\u8981\u5bf9\u65b0\u7684\u5408\u5e76\u6570\u7ec4\u91cd\u6392\u5e8f\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u4ece\u5bf9\u5df2\u5b58\u5728\u6570\u7ec4\u7684\u672b\u5c3e\u589e\u6dfb\u5143\u7d20\u5f00\u59cb\uff0c\u4f7f\u7528\u51fd\u6570array_push()\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? \/* \u521b\u5efa\u539f\u59cb\u6570\u7ec4 *\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n\/* \u52a0\u5165\u5230\u539f\u59cb\u6570\u7ec4\u4e2d *\/\r\narray_push($fruitArray, &quot;grape&quot;, &quot;pineapple&quot;, &quot;tomato&quot;);\r\n\/* \u901a\u8fc7\u5176\u952e\u503c\u5217\u51fa\u6bcf\u4e2a\u5143\u7d20*\/\r\nwhile (list($key,$value) = each($fruitArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n0 : apple\r\n1 : orange\r\n2 : banana\r\n3 : kiwi\r\n4 : pear\r\n5 : grape\r\n6 : pineapple\r\n7 : tomato\r\n<\/pre>\n<p>\u5f53\u60a8\u9700\u8981\u5bf9\u6570\u7ec4\u5f00\u5934\u6dfb\u52a0\u5143\u7d20\u65f6\uff0c\u4ee3\u7801\u5f88\u7c7b\u4f3c\u3002\u4e0d\u540c\u5904\u53ea\u662f\u51fd\u6570\u540d\uff1aarray_unshift() \u800c\u4e0d\u662farray_push()\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? \/* \u521b\u5efa\u539f\u59cb\u6570\u7ec4 *\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n\/* \u52a0\u5165\u5230\u539f\u59cb\u6570\u7ec4\u4e2d *\/\r\narray_unshift($fruitArray, &quot;grape&quot;, &quot;pineapple&quot;, &quot;tomato&quot;);\r\n\/* \u901a\u8fc7\u5176\u952e\u503c\u5217\u51fa\u6bcf\u4e2a\u5143\u7d20*\/\r\nwhile (list($key,$value) = each($fruitArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n0 : grape\r\n1 : pineapple\r\n2 : tomato\r\n3 : apple\r\n4 : orange\r\n5 : banana\r\n6 : kiwi\r\n7 : pear\r\n<\/pre>\n<p>\u51fd\u6570array_merge()\u5408\u5e76\u4e24\u4e2a\u6216\u66f4\u591a\u7684\u6570\u7ec4\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? \/* \u521b\u5efa\u539f\u59cb\u6570\u7ec4 *\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n&lt;? \/* \u521b\u5efa\u7b2c\u4e8c\u4e2a\u6570\u7ec4 *\/\r\n$vegArray = array(&quot;carrot&quot;, &quot;green beans&quot;, &quot;asparagus&quot;, &quot;artichoke&quot;, &quot;corn&quot;);\r\n\/* \u5408\u5e76\u4e3a\u4e00\u4e2a\u6570\u7ec4 *\/\r\n$goodfoodArray = array_merge($fruitArray, $vegArray);\r\n\/* \u901a\u8fc7\u5176\u952e\u503c\u5217\u51fa\u6bcf\u4e2a\u5143\u7d20*\/\r\nwhile (list($key,$value) = each($goodfoodArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n0 : apple\r\n1 : orange\r\n2 : banana\r\n3 : kiwi\r\n4 : pear\r\n5 : carrot\r\n6 : green beans\r\n7 : asparagus\r\n8 : artichoke\r\n9 : corn\r\n<\/pre>\n<p>\u73b0\u5728\u5df2\u5bf9\u6570\u7ec4\u8fdb\u884c\u4e86\u589e\u52a0\u5143\u7d20\u548c\u5408\u5e76\uff0c\u73b0\u5728\u6765\u7ec3\u4e60\u5220\u9664\u5143\u7d20\u51fd\u6570\u3002\u60a8\u80fd\u591f\u4f7f\u7528\u51fd\u6570array_pop()\u4ece\u4e00\u6570\u7ec4\u672b\u5c3e\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u5047\u5982\u4f7f\u7528\u51fd\u6570 array_shift()\uff0c\u5219\u4ece\u4e00\u6570\u7ec4\u5f00\u5934\u5220\u9664\u4e00\u4e2a\u5143\u7d20\u3002\u800c\u5b9e\u9645\u4e0a\u5f53\u60a8\u4ece\u6570\u7ec4\u5220\u9664\u5143\u7d20\u65f6\uff0c\u6b64\u5143\u7d20\u5bf9\u60a8\u800c\u8a00\u4ecd\u7136\u53ef\u7528\u2015\u2015\u5f53\u60a8\u4ece\u5df2\u5b58\u5728\u7684\u6570\u7ec4\u4e2d\u5bf9\u5143\u7d20\u8fdb\u884c pop \u6216 shift\u65f6\u3002<\/p>\n<p>\u4f7f\u7528array_pop()\u51fd\u6570\u4ece\u6570\u7ec4\u672b\u5c3e\u5220\u9664\u4e00\u4e2a\u503c\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?\r\n\/* \u521b\u5efa\u4e00\u6570\u7ec4*\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n\/* \u5728\u672b\u5c3e\u5f39\u51fa\u67d0\u503c *\/\r\n$popped = array_pop($fruitArray);\r\n\/* \u5217\u51fa\u65b0\u6570\u7ec4\u5185\u5bb9\uff0c\u8fde\u540c\u5f39\u51fa\u7684\u503c*\/\r\nwhile (list($key,$value) = each($fruitArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\necho &quot;&lt;br&gt;and finally, in $popped: $popped&quot;;\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n0 : apple\r\n1 : orange\r\n2 : banana\r\n3 : kiwi\r\nand finally, in $popped: pear\r\n<\/pre>\n<p>\u4e0b\u9762\uff0c\u4ece\u6570\u7ec4\u672b\u5c3e\u5220\u9664\u67d0\u503c\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?\r\n\/* \u521b\u5efa\u4e00\u6570\u7ec4*\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n\/* \u4ece\u6570\u7ec4\u5934\u90e8\u79fb\u51fa\u67d0\u503c *\/\r\n$shifted = array_shift($fruitArray);\r\n\/* \u5217\u51fa\u65b0\u6570\u7ec4\u7684\u5185\u5bb9\u8fde\u540c\u79fb\u51fa\u7684\u503c*\/\r\nwhile (list($key,$value) = each($fruitArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\necho &quot;&lt;br&gt;and finally, in $shifted: $shifted&quot;;\r\n?&gt;\r\n<\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n0 : orange\r\n1 : banana\r\n2 : kiwi\r\n3 : pear\r\nand finally, in $shifted: apple\r\n<\/pre>\n<p>\u6709\u5f88\u591a\u51fd\u6570\u80fd\u591f\u5e2e\u52a9\u60a8\u5bf9\u6570\u7ec4\u5143\u7d20\u6392\u5e8f\u3002\u4f46\u6211\u5c06\u4f1a\u6f14\u793a\u57fa\u672c\u7684\u6392\u5e8f\u4ee5\u5e2e\u52a9\u60a8\u4e86\u89e3\u5176\u8fc7\u7a0b\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;? \/* \u521b\u5efa\u539f\u59cb\u6570\u7ec4 *\/\r\n$fruitArray = array(&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;kiwi&quot;, &quot;pear&quot;);\r\n\/* \u6392\u5e8f *\/\r\nsort($fruitArray);\r\n\/* \u5bf9\u5176\u91cd\u8bbe\u4ee5\u6b63\u786e\u4ece\u5934\u5230\u5c3e\u663e\u793a\u6570\u7ec4 *\/\r\n\/* \u901a\u8fc7\u5176\u952e\u503c\u5217\u51fa\u6bcf\u4e2a\u5143\u7d20*\/\r\nwhile (list($key,$value) = each($fruitArray)) {\r\necho &quot;$key : $value&lt;br&gt;&quot;;\r\n}\r\n?&gt;\r\n<\/pre>\n<p>7.php\u4e2d\u57fa\u672c\u7684\u6570\u7ec4\u51fd\u6570<\/p>\n<p>integer count(mixed var)\/\/\u5728\u6570\u7ec4\u4e2d\u8fd4\u56de\u5143\u7d20\u7684\u4e2a\u6570\uff0c\u4e5f\u53ef\u7528\u4e8e\u4efb\u4f55\u7684\u53d8\u91cf<br \/>\nnumber max(array numbers)\/\/\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c<br \/>\nnumber min(array numbers)\/\/\u8fd4\u56de\u6570\u7ec4\u4e2d\u7684\u6700\u5c0f\u503c<br \/>\nboolean in_array(mixed needle,array haystack[,bollean strict])\/\/\u67e5\u627e\u6570\u7ec4\u4e2d\u7684\u503c\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u53ef\u9009\uff0c\u5f3a\u5236\u6267\u884c\u7c7b\u578b\u68c0\u67e5<br \/>\nmixed array_search(mixed needle,array haystack[,boolean strict])\/\/\u8fd4\u56de \u952e \u800c\u4e0d\u662f\u5e03\u5c14\u503c\uff0c<br \/>\n\u627e\u4e0d\u5230\u65f6\u8fd4\u56defalse\uff0c\u627e\u5230\u7684\u5143\u7d20\u5982\u679c\u6b63\u597d\u662f\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u5219\u8fd4\u56de0\uff0c\u800cPHP\u4f1a\u81ea\u52a8\u8f6c\u5316\u4e3afalse\u6240\u4ee5\u9700\u8981\u4f7f\u7528===\u5224\u65ad\uff0c<\/p>\n<p>\u4e3e\u4f8b\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;);\r\n$index = array_search(&quot;a&quot;,$a);\r\nif($index === false)\r\necho &quot;\u5728\u6570\u7ec4a\u4e2d\u672a\u53d1\u73b0\u5b57\u7b26\u2019a'&quot;;\r\nelse\r\necho &quot;Index = $index&quot;;\r\n\u8f93\u51fa\u7ed3\u679c\r\nIndex = 0\r\n<\/pre>\n<p>array array_reverse(array source[,bool preserve_keys])\/\/\u9006\u8f6c\u6570\u7ec4,\u751f\u6210\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u53ef\u9009\u53c2\u6570\u4e3atrue\u65f6\uff0c\u4fdd\u7559\u7d22\u5f15\u548c\u5143\u7d20\u4e4b\u95f4\u7684\u5173\u8054<br \/>\n\u4e3e\u4f8b\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = array(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;);\r\n$newa = array_reverse($a);\/\/\u76f4\u63a5\u7ffb\u8f6c\r\necho $newa&#x5B;0];\r\n$newb = array_reverse($a,true);\/\/\u4f9d\u65e7\u4fdd\u7559\u4e86\u7d22\u5f15\u548c\u5143\u7d20\u4e4b\u95f4\u7684\u5173\u8054\r\necho $newb&#x5B;0];\r\n\u8f93\u51fa\u7ed3\u679c\r\nfa\r\n<\/pre>\n<p>sort(array subject[,integer sort_flag])\/\/\u6839\u636e \u503c \u8fdb\u884c\u5347\u5e8f\u6392\u5217\uff08\u5728\u539f\u6570\u7ec4\u4e2d\u91cd\u65b0\u6392\u5217\u5143\u7d20\uff09<br \/>\nrsort(array subject[,integer sort_flag])\/\/\u6839\u636e \u503c \u8fdb\u884c\u964d\u5e8f\u6392\u5217\uff08\u5728\u539f\u6570\u7ec4\u4e2d\u91cd\u65b0\u6392\u5217\u5143\u7d20\uff09<br \/>\n\u53ef\u9009\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u4e3a\u6309\u6570\u5b57\u65b9\u5f0fSORT_NUMERIC\u8fd8\u662f\u5b57\u7b26\u4e32\u65b9\u5f0fSORT_STRING\u6216\u8005\u901a\u5e38\u7684\u65b9\u5f0fSORT_REGULAR\u6392\u5e8f<br \/>\nsort()\u3001rsort()\u53ef\u4ee5\u7528\u4e8e\u5173\u8054\u6570\u7ec4\uff0c\u4f46\u662f \u952e \u5c06\u4e22\u5931<br \/>\nasort(array subject[,integer sort_flag])\/\/\u6839\u636e \u503c \u8fdb\u884c\u5347\u5e8f\u6392\u5217\uff08\u5728\u539f\u6570\u7ec4\u4e2d\u91cd\u65b0\u6392\u5217\u5143\u7d20\uff09\uff0c\u4fdd\u6301\u952e\u503c\u5173\u8054<br \/>\narsort(array subject[,integer sort_flag])\/\/\u6839\u636e \u503c \u8fdb\u884c\u964d\u5e8f\u6392\u5217\uff08\u5728\u539f\u6570\u7ec4\u4e2d\u91cd\u65b0\u6392\u5217\u5143\u7d20\uff09\uff0c\u4fdd\u6301\u952e\u503c\u5173\u8054<br \/>\n\u5f53asort() arsort()\u7528\u4e8e\u975e\u5173\u8054\u6570\u7ec4\u65f6\uff0c\u5143\u7d20\u6309\u6392\u5e8f\u540e\u7684\u6b21\u5e8f\u91cd\u65b0\u6392\u5217\uff0c\u4f46\u662f\u8bbf\u95ee\u5143\u7d20\u7684\u7d22\u5f15\u4e0d\u6539\u53d8<br \/>\ninteger ksort(ayyay subject [,integer sort_flag])\/\/\u6839\u636e \u952e\u6216\u7d22\u5f15 \u8fdb\u884c\u5347\u5e8f\u6392\u5217<br \/>\ninteger krsort(ayyay subject [,integer sort_flag])\/\/\u6839\u636e \u952e\u6216\u7d22\u5f15 \u8fdb\u884c\u964d\u5e8f\u6392\u5217<br \/>\nusort(array subject, string compare_function)\/\/\u6839\u636e\u7528\u6237\u5b9a\u4e49\u6392\u5e8f\uff0c\u7528\u6237\u5b9a\u4e49\u81ea\u5df1\u7684\u6392\u5e8f\u89c4\u5219\u51fd\u6570\uff0c\u4f46\u51fd\u6570\u5fc5\u987b\u7b26\u5408<br \/>\nuasort(array subject, string compare_function)\/\/integer my_compare_function(mixed a, mixed b),a&gt;b\u8fd4\u56de1\uff0c<br \/>\na uksort(array subject, string compare_function)\/\/a\u7b49\u4e8eb\u65f6\u8fd4\u56de0<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$numbers = array(16,3,2,171,5,24,6,19);\r\nsort($numbers);\r\nforeach($numbers as $n)\r\necho $n.&quot; &quot;;\r\n$numbers = array(16,3,2,171,5,24,6,19);\r\nrsort($numbers);\r\nforeach($numbers as $n)\r\necho $n.&quot; &quot;;\r\n$numbers = array(16,3,2,171,5,24,6,19);\r\nsort($numbers,SORT_STRING);\r\nforeach($numbers as $n)\r\necho $n.&quot; &quot;;\r\n$a = array(&quot;o&quot;=&gt;&quot;kk&quot;,&quot;e&quot;=&gt;&quot;zz&quot;,&quot;z&quot;=&gt;&quot;hh&quot;,&quot;a&quot;=&gt;&quot;rr&quot;);\r\nasort($a);\r\nforeach ($a as $keyname=&gt;$keyvalue)\r\necho $keyvalue;\r\n$a = array(&quot;o&quot;=&gt;&quot;kk&quot;,&quot;e&quot;=&gt;&quot;zz&quot;,&quot;z&quot;=&gt;&quot;hh&quot;,&quot;a&quot;=&gt;&quot;rr&quot;);\r\nksort($a);\r\nforeach ($a as $keyname=&gt;$keyvalue)\r\necho $keyvalue;\r\n\/\/\u57fa\u4e8e\u957f\u5ea6\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\r\nfunction cmp_length($a,$b)\r\n{\r\nif(strlen($a) &lt; strlen($b))\r\nreturn -1;\r\nif(strlen($a) &gt; strlen($b))\r\nreturn 1;\r\nreturn 0;\r\n}\r\n$animals = array(&quot;cow&quot;,&quot;ox&quot;,&quot;monkey&quot;,&quot;mimi&quot;);\r\nusort($animals,&quot;cmp_length&quot;);\r\nforeach($animals as $an)\r\necho $an;\r\n\u8f93\u51fa\u7ed3\u679c\r\n2 3 5 6 16 19 24 171 171 24 19 16 6 5 3 2 16 171 19 2 24 3 5 6 hhkkrrzzrrzzkkhhoxcowmimimonkey\r\n<\/pre>\n<p>array_merge($a,$b)\/\/\u7ec4\u5408\u6570\u7ec4\uff0c\u4e2a\u4eba\u8ba4\u4e3a\u662f\u6bd4\u8f83\u6709\u8da3\u7684\u51fd\u6570\u4e4b\u4e00\uff0c\u4ece\u4e24\u4e2a\u6570\u7ec4\u751f\u6210\u4e00\u4e2a\u6570\u7ec4\uff0c\u5177\u6709\u76f8\u540c \u952e \u7684\u503c\u4f1a\u88ab\u8986\u76d6<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = array(&quot;name&quot;=&gt;&quot;zhangsan&quot;,10,100);\r\n$b = array(&quot;name&quot;=&gt;&quot;lisi&quot;,4,6,8);\r\n$c = array_merge($a,$b);\r\nvar_dump($c);\r\n\r\n\u8f93\u51fa\u7ed3\u679c\r\narray(6) { &#x5B;&quot;name&quot;]=&gt; string(4) &quot;lisi&quot; &#x5B;0]=&gt; int(10) &#x5B;1]=&gt; int(100) &#x5B;2]=&gt; int(4) &#x5B;3]=&gt; int(6) &#x5B;4]=&gt; int(8) }\r\n<\/pre>\n<p>array array_combine(array $a,array $b)\/\/a\u6570\u7ec4\u7684\u503c\u4e3a\u65b0\u6570\u7ec4\u7684\u952e\uff0cb\u6570\u7ec4\u7684\u503c\u4e3a\u65b0\u6570\u7ec4\u7684\u503c\uff0c\u6570\u7ec4\u957f\u5ea6\u4e0d\u540c\u65f6\uff0c\u8fd4\u56defalse<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = array(&quot;name&quot;,&quot;math&quot;,&quot;china&quot;);\r\n$b = array(&quot;zhangsan&quot;,4,6);\r\n$c = array_combine($a,$b);\r\nvar_dump($c);\r\n\u8f93\u51fa\u7ed3\u679c\r\narray(3) { &#x5B;&quot;name&quot;]=&gt; string(8) &quot;zhangsan&quot; &#x5B;&quot;math&quot;]=&gt; int(4) &#x5B;&quot;china&quot;]=&gt; int(6) }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u6570\u7ec4\u7684\u5b9a\u4e49\u548c\u521d\u59cb\u5316 \u4ec0\u4e48\u662f\u6570\u7ec4\uff1f\u6570\u7ec4\u662f\u4e00\u79cd\u7f16\u7a0b\u7ed3\u6784\uff0c\u5b83\u662f\u4e00\u4e2a\u5b58\u50a8\u4e00\u7ec4\u6216\u4e00\u7cfb\u5217\u6570\u503c\u7684\u53d8\u91cf\u3002 \u6bd4\u5982\u4eba\u53e3\u666e\u67e5\u65f6\u5bf9 [&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-747","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/747","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=747"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/747\/revisions"}],"predecessor-version":[{"id":5255,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/747\/revisions\/5255"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}