{"id":810,"date":"2024-06-05T20:36:41","date_gmt":"2024-06-05T12:36:41","guid":{"rendered":"https:\/\/cn.raksmart.com\/blog\/host\/4215.html"},"modified":"2024-06-05T20:36:41","modified_gmt":"2024-06-05T12:36:41","slug":"php%e5%9f%ba%e7%a1%80%e5%ad%a6%e4%b9%a0%e4%b9%8b%e6%95%b0%e7%bb%84%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/cn.raksmart.com\/blog\/knowledge\/810.html","title":{"rendered":"PHP\u57fa\u7840\u5b66\u4e60\u4e4b\u6570\u7ec4\u4ecb\u7ecd"},"content":{"rendered":"<div class=\"entry-content e-content\" itemprop=\"description articleBody\">\n<p>php\u4e2d\uff0c\u6570\u7ec4\u7684\u4e0b\u6807\u80fd\u591f\u6574\u6570\uff0c\u4e5f\u53ef\u6240\u4ee5\u5b57\u7b26\u4e32\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u6b21\u5e8f\u4e0d\u662f\u7531\u4e0b\u6807\u9009\u62e9\uff0c\u800c\u662f\u7531\u5176\u201c\u53c2\u4e0e\u201d\u7684\u6b21\u5e8f\u9009\u62e9<\/p>\n<p>Raksmart<strong><a rel=\"noreferrer noopener\" aria-label=\"\u7f8e\u56fd\u670d\u52a1\u5668\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/cn.raksmart.com\/\" target=\"_blank\">\u7f8e\u56fd\u670d\u52a1\u5668<\/a><\/strong>\u5c0f\u7f16\u6574\u7406\u7684\u8fd9\u7bc7\u6587\u7ae0PHP\u57fa\u7840\u5b66\u4e60\u4e4b\u6570\u7ec4\u4ecb\u7ecd\uff0c\u8be6\u7ec6\u8bf4\u660e\u6587\u7ae0\u4e2d\u76f8\u5173PHP\u57fa\u7840\u5b66\u4e60 \u6570\u7ec4\u6280\u80fd\u4e0e\u5e38\u8bc6\uff0c\u6b22\u8fce\u80fd\u7ed9\u5927\u5bb6\u4e00\u4e9b\u5728\u8fd9\u65b9\u9762\u7684\u652f\u6491\u548c\u5e2e\u52a9\uff01\u4e0b\u9762\u662f\u8be6\u7ec6\u5185\u5bb9\uff1a<\/p>\n<p>\u6570\u7ec4\u57fa\u7840\uff1a<\/p>\n<p>php\u4e2d\uff0c\u6570\u7ec4\u7684\u4e0b\u6807\u53ef\u4ee5\u6574\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32<\/p>\n<p>php\u4e2d\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u987a\u5e8f\u4e0d\u662f\u7531\u4e0b\u6807\u51b3\u5b9a\uff0c\u800c\u662f\u7531\u5176\u201c\u52a0\u5165\u201d\u7684\u987a\u5e8f\u51b3\u5b9a<\/p>\n<p>\u5b9a\u4e49\uff1a<\/p>\n<p>$arr1=array(\u5143\u7d201\uff0c\u5143\u7d202\uff0c\u3002\u3002\u3002\u3002\u3002\u3002);<\/p>\n<p>array(1,1.1,5,\u2019abc\u2019,true,false);\/\/\u53ef\u4ee5\u5b58\u50a8\u4efb\u4f55\u6570\u636e\uff0c\u6b64\u65f6\u4e3a\u9ed8\u8ba4\u4e0b\u6807<\/p>\n<p>array(2=&gt;1,4=&gt;1.1,3=&gt;5,7=&gt;\u2019abc\u2019,0=&gt;true);\/\/\u4e0b\u6807\u53ef\u4efb\u610f\u8bbe\u5b9a(\u65e0\u9700\u987a\u5e8f\uff0c\u65e0\u9700\u8fde\u7eed)<\/p>\n<p>array(2=&gt;1,1.1,1=&gt;5,\u2019abc\u2019,0=&gt;true);\/\/\u53ef\u4ee5\u52a0\u4e0b\u6807\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u52a0\uff0c\u4e0d\u52a0\u4e0b\u6807\u5219\u4e3a\u9ed8\u8ba4\u4e0b\u6807<\/p>\n<p>\/\/\u9ed8\u8ba4\u4e0b\u6807\u89c4\u5219\uff1a\u524d\u9762\u5df2\u7ecf\u7528\u8fc7\u7684\u6700\u5927\u6570\u5b57\u4e0b\u6807+1<\/p>\n<p>\/\/\u8fd9\u4e2a\u6570\u5b57\u7684\u4e0b\u6807\u5206\u522b\u662f\uff1a2\uff0c3\uff0c1\uff0c4\uff0c0<\/p>\n<p>array(2=&gt;1,\u2019dd\u2019=&gt;5,1=&gt;1.1,\u2019abc\u2019,0=&gt;true);\/\/\u6df7\u5408\u4e0b\u6807\uff0c\u540c\u6837\u9075\u5faa\u9ed8\u8ba4\u4e0b\u6807\u89c4\u5219<\/p>\n<p>array(-2=&gt;1,\u2019dd\u2019=&gt;5,1.1,\u2019abc\u2019,true);\/\/\u8d1f\u6570\u4e0b\u6807\u4e0d\u7b97\u5728\u6574\u6570\u4e0b\u6807\u4e2d\uff0c\u800c\u53ea\u5f53\u4f5c\u5b57\u7b26\u4e0b\u6807<\/p>\n<p>\/\/\u5219\u8fd9\u4e2a\u6570\u7ec4\u6700\u540e\u4e09\u9879\u7684\u4e0b\u6807\u4e3a\uff1a0,1,2<\/p>\n<p>array(2.7=&gt;1,\u2019dd\u2019=&gt;5,1=&gt;1.1,\u2019abc\u2019,true);\/\/\u6d6e\u70b9\u6570\u4e0b\u6807\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u6574\u6570\uff0c\u4e14\u76f4\u63a5\u53bb\u6389\u5c0f\u6570\u90e8\u5206<\/p>\n<p>array(\u201c2.7\u2033=&gt;1,\u2019dd\u2019=&gt;5,\u201d11\u2033=&gt;1.1,\u2019abc\u2019,true);\/\/\u7eaf\u6570\u5b57\u5b57\u7b26\u4e32\u4e0b\u6807\uff0c\u5f53\u4f5c\u6570\u5b57\u770b\u5f85<\/p>\n<p>array(2=&gt;1,\u2019dd\u2019=&gt;5,true=&gt;1.1,\u2019abc\u2019,false=&gt;true);\/\/\u5e03\u5c14\u503c\u5f53\u4f5c\u4e0b\u6807\uff0c\u5219true\u4e3a1\uff0cfalse\u4e3a0<\/p>\n<p>array(2=&gt;1,\u2019dd\u2019=&gt;5,2=&gt;1.1,\u2019abc\u2019,true);\/\/\u5982\u679c\u4e0b\u6807\u8ddf\u524d\u9762\u7684\u91cd\u590d\uff0c\u5219\u5355\u7eaf\u8986\u76d6\u524d\u9762\u540c\u540d\u4e0b\u6807\u7684\u503c<\/p>\n<p>\u5176\u4ed6\u5f62\u5f0f\uff1a<\/p>\n<p>$arr1[]=1;<\/p>\n<p>$arr1[]=5;<\/p>\n<p>$arr1[]=1.1;<\/p>\n<p>\u2026\u2026\/\/\u76f4\u63a5\u5728\u53d8\u91cf\u540e\u9762\u4f7f\u7528[]\uff0c\u5c31\u6210\u4e3a\u6570\u7ec4\uff0c\u5e76\u4f9d\u6b21\u8d4b\u503c<\/p>\n<p>$arr2[\u2018aa\u2019]=1;<\/p>\n<p>$arr2[\u2018bb\u2019]=5;<\/p>\n<p>$arr2[5]=1.1;<\/p>\n<p>\u2026\u2026\/\/\u8fd9\u79cd\u5f62\u5f0f\u5199\u7684\u4e0b\u6807\uff0c\u5176\u5b9e\u8ddf\u4f7f\u7528array\u8bed\u6cd5\u7ed3\u6784\u51e0\u4e4e\u4e00\u6837<\/p>\n<p>\u6570\u7ec4\u7684\u5206\u7c7b\uff1a<\/p>\n<p>\u4ece\u952e\u503c\u5173\u7cfb\u5206\u4e3a\uff1a<\/p>\n<p>\u5173\u8054\u6570\u7ec4\uff1a\u901a\u5e38\u662f\u6307\u4e0b\u6807\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u4e14\u8be5\u5b57\u7b26\u4e32\u5927\u4f53\u53ef\u4ee5\u8868\u8fbe\u51fa\u6570\u636e\u7684\u542b\u4e49\u7684\u6570\u7ec4<\/p>\n<p>\u4f8b\uff1a$person=array(\u201cname\u201d=&gt;\u201dpoe\u201d,\u201dage\u201d=&gt;18,\u201dedu\u201d=&gt;\u201d\u5927\u5b66\u6bd5\u4e1a\u201d);<\/p>\n<p>\u7d22\u5f15\u6570\u7ec4\uff1a\u901a\u5e38\u662f\u6307\u4e00\u4e2a\u6570\u7ec4\u7684\u4e0b\u6807\u4e25\u683c\u7684\u4ece0\u5f00\u59cb\u7684\u8fde\u7eed\u7684\u6570\u5b57\u4e0b\u6807\u2013\u8ddfjs\u6570\u7ec4\u7c7b\u4f3c<\/p>\n<p>\u4ece\u6570\u7ec4\u5c42\u6b21\u4e3a\u5206\uff1a<\/p>\n<p>\u4e00\u7ef4\u6570\u7ec4\uff1a\u5c31\u662f\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u503c\uff0c\u90fd\u662f\u4e00\u4e2a\u666e\u901a\u503c(\u975e\u6570\u7ec4\u503c)<\/p>\n<p>\u4f8b\uff1a$person=array(\u201cname\u201d=&gt;\u201dpoe\u201d,\u201dage\u201d=&gt;18,\u201dedu\u201d=&gt;\u201d\u5927\u5b66\u6bd5\u4e1a\u201d);<\/p>\n<p>\u4e8c\u7ef4\u6570\u7ec4\uff1a\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u9879\uff0c\u53c8\u662f\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u3002<\/p>\n<p>$person=array(<\/p>\n<p>\u201cname\u201d=&gt;array(\u201cxiaohua\u201d,\u201dxiaofang),<\/p>\n<p>\u201cage\u201d=&gt;array(18,22),<\/p>\n<p>\u201cedu\u201d=&gt;array(\u201c\u5927\u5b66\u6bd5\u4e1a\u201d,\u201d\u5c0f\u5b66\u201d,)<\/p>\n<p>);<\/p>\n<p>\u591a\u7ef4\u6570\u7ec4\uff1a\u4f9d\u6b21\u7c7b\u63a8\u3002\u3002\u3002<\/p>\n<p>\u591a\u7ef4\u6570\u7ec4\u7684\u4e00\u822c\u8bed\u6cd5\u5f62\u5f0f\uff1a<\/p>\n<p>$v1=\u6570\u7ec4\u540d[\u4e0b\u6807][\u4e0b\u6807][\u2026\u2026]<\/p>\n<p>\u6570\u7ec4\u7684\u904d\u5386\uff1a<\/p>\n<p>\u904d\u5386\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n<p>foreach($arr as[$key=&gt;]$value){<\/p>\n<p>\/\/\u8fd9\u91cc\u5c31\u53ef\u4ee5\u5bf9$key and$value\u8fdb\u884c\u6240\u6709\u53ef\u80fd\u7684\u64cd\u4f5c\u2013\u56e0\u4e3a\u4ed6\u4eec\u5c31\u662f\u4e00\u4e2a\u53d8\u91cf<\/p>\n<p>\/\/$key\u4ee3\u8868\u6bcf\u6b21\u53d6\u5f97\u5143\u7d20\u7684\u4e0b\u6807\uff0c\u53ef\u80fd\u662f\u6570\u5b57\uff0c\u4e5f\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32<\/p>\n<p>\/\/$value\u4ee3\u8868\u6bcf\u6b21\u53d6\u5f97\u5143\u7d20\u7684\u503c\uff0c\u53ef\u80fd\u662f\u5404\u79cd\u7c7b\u578b<\/p>\n<p>\/\/\u6b64\u5faa\u73af\u7ed3\u6784\u4f1a\u4ece\u6570\u7ec4\u7684\u7b2c\u4e00\u9879\u4e00\u76f4\u904d\u5386\u5230\u6700\u540e\u4e00\u9879\uff0c\u7136\u540e\u7ed3\u675f<\/p>\n<p>}<\/p>\n<p>\u6570\u7ec4\u6307\u9488\u548c\u904d\u5386\u539f\u7406\uff1a<\/p>\n<p>\u6bcf\u4e2a\u6570\u7ec4\uff0c\u5176\u5185\u90e8\u90fd\u6709\u4e00\u4e2a\u201c\u6307\u9488\u201d\uff0c\u8be5\u6307\u9488\u51b3\u5b9a\u4e86\u8be5\u6570\u7ec4\u5f53\u524d\u53d6\u503c\u7684\u65f6\u5019\u53d6\u5230\u7684\u5143\u7d20<\/p>\n<p>foreach\u904d\u5386\u8fc7\u7a0b\u4e2d\uff0c\u90fd\u662f\u4f9d\u8d56\u4e8e\u8be5\u6307\u9488\u800c\u8fdb\u884c\u7684\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a$arr1=array(2=&gt;1,\u2019dd\u2019=&gt;5,1=&gt;1.1,\u2019abc\u2019,0=&gt;true);<\/p>\n<p>wKioL1ZNx1Sxflt6AAAnrLtN90Q498.jpg<\/p>\n<p>\u6307\u9488\u9664\u4e86\u8d1f\u8d23foreach\u5faa\u73af\u7684\u4f4d\u7f6e\u8bbe\u5b9a\u4e4b\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u51fd\u6570\u4e5f\u4f9d\u8d56\u4e8e\u6307\u9488\uff1a<\/p>\n<p>1\uff1a$v1=current($arr1);\/\/\u53d6\u5f97$arr1\u4e2d\u5f53\u524d\u6307\u9488\u6307\u5411\u7684\u5143\u7d20\u7684\u503c\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5411\u5143\u7d20\uff0c\u5219\u4e3afalse<\/p>\n<p>2\uff1a$v1=key($arr1);\/\/\u53d6\u5f97$arr1\u4e2d\u5f53\u524d\u6307\u9488\u6307\u5411\u7684\u5143\u7d20\u7684\u4e0b\u6807\uff0c\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n<p>3\uff1a$v1=next($arr1);\/\/\u5c06\u6307\u9488\u79fb\u5411\u201c\u4e0b\u4e00\u4e2a\u5143\u7d20\u201d\uff0c\u7136\u540e\u53d6\u5f97\u8be5\u4e0b\u4e00\u4e2a\u5143\u7d20\u7684\u503c<\/p>\n<p>4\uff1a$v1=prev($arr1);\/\/\u5c06\u6307\u9488\u79fb\u5411\u201c\u4e0a\u4e00\u4e2a\u5143\u7d20\u201d\uff0c\u7136\u540e\u53d6\u5f97\u8be5\u4e0a\u4e00\u4e2a\u5143\u7d20\u7684\u503c<\/p>\n<p>5\uff1a$v1=reset($arr1);\/\/\u5c06\u6307\u9488\u79fb\u5411\u201c\u7b2c\u4e00\u4e2a\u5143\u7d20\u201d\uff0c\u5e76\u53d6\u5f97\u8be5\u5143\u7d20\u7684\u503c<\/p>\n<p>6\uff1a$v1=end($arr1);\/\/\u5c06\u6307\u9488\u79fb\u5411\u201c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u201d\uff0c\u5e76\u53d6\u5f97\u8be5\u5143\u7d20\u7684\u503c<\/p>\n<p>7\uff1a$v1=each($arr1);\/\/\u53d6\u5f97\u5f53\u524d\u5143\u7d20\u7684\u4e0b\u6807\u548c\u503c\uff0c\u7136\u540e\u79fb\u52a8\u6307\u9488\u5230\u4e0b\u4e00\u4e2a\u4f4d\u7f6e \u66f4\u591a\u7684\u76f8\u5173\u5185\u5bb9\u53ef\u4ee5\u9605\u8bfb <a href=\"https:\/\/cn.raksmart.com\/blog\/knowledge\/781.html\" title>\u4ec0\u4e48\u662fWHM\uff1f<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u4e2d\uff0c\u6570\u7ec4\u7684\u4e0b\u6807\u80fd\u591f\u6574\u6570\uff0c\u4e5f\u53ef\u6240\u4ee5\u5b57\u7b26\u4e32\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u6b21\u5e8f\u4e0d\u662f\u7531\u4e0b\u6807\u9009\u62e9\uff0c\u800c\u662f\u7531\u5176\u201c\u53c2\u4e0e\u201d\u7684\u6b21\u5e8f\u9009\u2026 <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[644],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-knowledge","tag-php"],"_links":{"self":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":0,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"wp:attachment":[{"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.raksmart.com\/blog\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}