{"id":29,"date":"2023-06-05T12:58:09","date_gmt":"2023-06-05T04:58:09","guid":{"rendered":"http:\/\/pro369.com\/php\/?p=29"},"modified":"2019-07-29T08:21:00","modified_gmt":"2019-07-29T08:21:00","slug":"%e4%bd%bf%e7%94%a8php%e7%a8%8b%e5%bc%8f%e7%9a%84%e4%ba%94%e5%80%8b%e5%b0%8f%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/por.tw\/php\/%e4%bd%bf%e7%94%a8php%e7%a8%8b%e5%bc%8f%e7%9a%84%e4%ba%94%e5%80%8b%e5%b0%8f%e6%8a%80%e5%b7%a7\/","title":{"rendered":"\u4f7f\u7528php\u7a0b\u5f0f\u7684\u4e94\u500b\u5c0f\u6280\u5de7"},"content":{"rendered":"<p><strong><font size=\"4\" style=\"background-color: #ffff00\">\u4f7f\u7528php\u7a0b\u5f0f\u7684\u4e94\u500b\u5c0f\u6280\u5de7<\/font><br \/> &nbsp;<br \/> <font color=\"#008000\"><span style=\"background-color: #ffffff\">php\u7a0b\u5f0f\u7684\u4e00\u4e9b\u5c0f\u6280\u5de7\uff0c\u9019\u4e9b\u6bd4\u8f03\u57fa\u790e\uff0c\u7e3d\u7d50\u4e00\u4e0b\uff08<\/span><\/font><\/strong><strong><font color=\"#008000\"><span style=\"background-color: #ffffff\">\u5982\u679c\u4f60\u662f\u8001\u9ce5\u90a3\u5c31\u7576\u6210\u8907\u7fd2\u5427<\/span><\/font><\/strong><strong><font color=\"#008000\"><span style=\"background-color: #ffffff\">\uff09\u3002<\/span><\/font><\/strong><\/p>\n<p> 1. str_replace<\/p>\n<p> str_replace\u662f\u975e\u5e38\u5e38\u5e38\u5e38\u5e38\u7528\u7684php\u51fd\u6578,\u7528\u65bc\u5b57\u4e32\u7f6e\u63db\uff0c\u7d93\u5e38\u770b\u5230\u67d0\u4e9bphp\u65b0\u4eba\u70ba\u4e86\u7f6e\u63db\u4e00\u6279\u5b57\u4e32\uff0c\u5beb\u4e86\u597d\u591a\u884cstr_replace\uff0c\u5be6\u5728\u662f\u6158\u4e0d\u5fcd\u7779\u3002<\/p>\n<p> \u6bd4\u5982\u9019\u500b\u4f8b\u5b50:<\/p>\n<p> $str = &#39;\u67d0\u4eba\u7684\u68f2\u606f\u5730 &#8212; www.abc.net&#39;;<\/p>\n<p> $str = str_replace(&#39;\u67d0\u4eba&#39;, &#39;\u58de\u4eba&#39;, $str);<\/p>\n<p> $str = str_replace(&#39;\u7684&#39;, &#39;di&#39;, $str);<\/p>\n<p> $str = str_replace(&#39;\u68f2\u606f\u5730&#39;, &#39;\u8c6c\u7aa9\u7aa9&#39;, $str);<\/p>\n<p> $str = str_replace(&#39;www.abc.net&#39;, &#39;abc.net&#39;, $str);<\/p>\n<p> \u4ee5\u4e0a\uff0c\u7f6e\u63db\u4e864\u6b21\u5b57\u4e32\uff0c\u5be6\u969b\u53ea\u8981\u63db\u500b\u5beb\u6cd5\uff0c\u4e00\u884c\u5c31\u641e\u5b9a\u4e86:<\/p>\n<p> $str = &#39;\u67d0\u4eba\u7684\u68f2\u606f\u5730 &#8212; www.abc.net&#39;;<\/p>\n<p> $str = str_replace(array(&#39;\u67d0\u4eba&#39;, &#39;\u7684&#39;, &#39;\u68f2\u606f\u5730&#39;, &#39;www.abc.net&#39;), array(&#39;\u58de\u4eba&#39;, &#39;di&#39;, &#39;\u8c6c\u7aa9\u7aa9&#39;, &#39;abc.net&#39;), $str);<\/p>\n<p> &nbsp;<\/p>\n<p> 2. array<\/p>\n<p> \u7d93\u5e38\u770b\u5230\u6709\u4eba\u62ff\u9663\u5217\u9019\u6a23\u5beb:<\/p>\n<p> echo $arr[some_key];<\/p>\n<p> \u4e0a\u9762\u9019\u884c\u4ee3\u78bc\u80fd\u8dd1\uff0c\u770b\u4e0a\u53bb\u4e5f\u6c92\u4ec0\u9ebc\u5927\u554f\u984c\uff0c\u4f46\u662f\u5982\u679c\u4f60\u628aphp.ini\u7684error notice\u958b\u555f\u7684\u8a71\uff0c\u6703\u6536\u5230\u4e00\u5927\u6279error\u3002<br \/> php\u89e3\u6790\u5668\u9996\u5148\u662f\u62ff\u300csome_key\u300d\u7576\u4f5c\u4e00\u500b\u5e38\u91cf\u4f86\u89e3\u91cb\u7684\uff0c\u4f46\u5982\u679c\u6c92\u6709\u5b9a\u7fa9some_key\u9019\u6a23\u4e00\u500b\u5e38\u91cf\uff0c\u89e3\u6790\u5668\u9084\u662f\u5f88\u5bec\u5bb9\u7684\u628a\u5b83\u7576\u4f5c\u4e86\u4e00\u500b\u5b57\u4e32\u4f86\u770b\u5f85\u3002<br \/> \u56e0\u6b64\u65b0\u4eba\u540c\u5b78\u5011\u6700\u597d\u5beb\u5b8c\u6574\u4e00\u9ede:<\/p>\n<p> echo $arr[&#39;some_key&#39;];<\/p>\n<p> \u9019\u6a23\u5c31\u6c92\u6709\u554f\u984c\u4e86\uff0c\u5982\u679c\u4f60\u8981\u628a\u5b83\u653e\u5728\u96d9\u5f15\u865f\u4e2d\u9023\u7528\uff0c\u4e5f\u4e0d\u80fd\u7701\u6389\u5f15\u865f\uff0c\u53ef\u4ee5\u9019\u6a23\u5beb:<\/p>\n<p> echo &quot;\u9019\u662f\u6df7\u5728\u96d9\u5f15\u865f\u4e2d\u7684\u5b57\u4e32{$arr[&#39;some_key&#39;]}&quot;;<\/p>\n<p> &nbsp;<\/p>\n<p> 3. \u985e\u578b\u6232\u6cd5<\/p>\n<p> \u985e\u578b\u6232\u6cd5\u76f8\u7576\u597d\u7528\uff0c\u6bd4\u5982\u6709\u4e00\u500b\u8868\u55ae\u9001\u51fa\u904e\u4f86\u7684\u8b8a\u91cf\uff0c\u6a19\u6e96\u60c5\u6cc1\u4e0b\u5b83\u61c9\u8a72\u662f\u6574\u578b\u7684\uff0c\u6709\u6642\u5019\u5077\u61f6\u7701\u53bb\u6821\u9a57\u7684\u5beb\u6cd5\u53ef\u4ee5\u662f\u9019\u6a23\u7684:<\/p>\n<p> $intVar = (int)$_POST[&#39;post_var&#39;];<\/p>\n<p> \u518d\u6bd4\u5982\u9663\u5217\uff0c\u6709\u6642\u5019\u5beb\u9375\u503c\u8981\u6253\u5f15\u865f\u662f\u4e0d\u662f\u5f88\u4e0d\u723d\u554a\uff0c\u6211\u5011\u53ef\u4ee5\u628a\u5b83\u8f49\u63db\u6210object,\u6bd4\u5982:<\/p>\n<p> $arr = array(&#39;name&#39; =&gt; &#39;volcano&#39;, &#39;sex&#39; =&gt; &#39;male&#39;);<\/p>\n<p> $arr = (object)$arr;<\/p>\n<p> echo $arr-&gt;name;<\/p>\n<p> echo $arr-&gt;sex;<\/p>\n<p> \u662f\u4e0d\u662f\u5f88\u7701\u4e8b?<\/p>\n<p> &nbsp;<\/p>\n<p> 4. lambda\u51fd\u6578<\/p>\n<p> lamda\u51fd\u6578\u548carray_*\u7cfb\u5217\u51fd\u6578\u4f7f\u7528\u6709\u5947\u6548\uff0c\u62ffphp\u624b\u518a\u4e0a\u7684\u4e00\u500b\u4f8b\u5b50\u4f86\u8aaa\uff1a<\/p>\n<p> &lt;?php<\/p>\n<p> $av = array(&quot;the &quot;, &quot;a &quot;, &quot;that &quot;, &quot;this &quot;);<\/p>\n<p> array_walk($av, create_function(&#39;&amp;$v,$k&#39;, &#39;$v = $v . &quot;mango&quot;;&#39;));<\/p>\n<p> print_r($av);<\/p>\n<p> ?&gt;<\/p>\n<p> \u81f3\u5c11\u7701\u4e86\u4e00\u500bfor\u8ff4\u5708<\/p>\n<p> &nbsp;<\/p>\n<p> 5. \u5d4c\u5957\u8ff4\u5708\u986f\u793a\u8868\u683c\u7684\u55ae\u5143\u683c<\/p>\n<p> \u5d4c\u5957\u8ff4\u5708\u986f\u793a\u8868\u683c\u7684\u55ae\u5143\u683c\uff0c\u9019\u662f\u4e00\u500b\u5f88\u8001\u7684\u8a71\u984c\u54e6\uff0c\u5f80\u5f80\u6703\u8981\u5728\u67d0\u500b\u55ae\u5143\u683c\u5f8c\u908a\u52a0\u500b\u689d\u4ef6\u5224\u65b7\u4ec0\u9ebc\u7684\uff0c\u8003\u616e\u662f\u4e0d\u662f\u8981\u8f38\u51fatr\u6291\u6216\u662ftd\u6a19\u7c64\u3002<\/p>\n<p> \u4ffa\u9019\u88e1\u4ecb\u7d39\u4e00\u500b\u8fa6\u6cd5\uff0c\u5229\u7528array_chunk\u51fd\u6578\u80fd\u5920\u6bd4\u8f03\u5de5\u6574\u7684\u8f38\u51fahtml\uff0c\u898b\u4e0b\u4f8b\uff0c\u9019\u500b\u4f8b\u5b50\u8981\u8f38\u51fa\u4e00\u500b4\u884c6\u5217\u7684\u8868\u683c\uff1a<\/p>\n<p> &lt;?php<\/p>\n<p> $arr = range(1, 24); \/\/\u9019\u500b\u6703\u751f\u6210\u4e00\u500b\u9663\u5217array(1,2,3,4&#8230;.24)<\/p>\n<p> $arr = array_chunk($arr, 6);<\/p>\n<p> \/\/ output table<\/p>\n<p> ?&gt;<\/p>\n<p> &lt;table&gt; &lt;?php foreach($arr as $row): ?&gt; &lt;tr&gt; &lt;?php foreach($row as $col):?&gt; &lt;td&gt;&lt;?php echo $col?&gt;&lt;\/td&gt; &lt;?php endforeach;?&gt; &lt;\/tr&gt; &lt;?php endforeach;?&gt; &lt;\/table&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528php\u7a0b\u5f0f\u7684\u4e94\u500b\u5c0f\u6280\u5de7 &nbsp; php\u7a0b\u5f0f\u7684\u4e00\u4e9b\u5c0f\u6280\u5de7\uff0c\u9019\u4e9b\u6bd4\u8f03\u57fa\u790e\uff0c\u7e3d\u7d50\u4e00\u4e0b\uff08\u5982\u679c\u4f60\u662f\u8001\u9ce5\u90a3\u5c31\u7576\u6210 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[22],"class_list":["post-29","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/29"}],"collection":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media\/401"}],"wp:attachment":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}