{"id":152,"date":"2023-02-18T21:05:40","date_gmt":"2023-02-18T13:05:40","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=152"},"modified":"2023-02-18T21:06:03","modified_gmt":"2023-02-18T13:06:03","slug":"php-array-delete-element","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/php-array-delete-element\/","title":{"rendered":"PHP\u5220\u9664\u6570\u7ec4\u4e2d\u67d0\u5143\u7d20"},"content":{"rendered":"<h3>array_splice<\/h3>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-php\">$arr = array(1, 2, 3, 4, 5);\n$key = array_search(3, $arr);\n\nif ($key !== false)\n    array_splice($arr, $key, 1);\nvar_dump($arr);<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code>array(4) { [0]=&gt; int(1) [1]=&gt; int(2) [2]=&gt; int(4) [3]=&gt; int(5) }<\/code><\/pre>\n<h3>array_splice<\/h3>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-php\">$arr = array(1, 2, 3, 4, 5);\nforeach ($arr as $key =&gt; $value) {\n    if ($value === 3)\n        unset($arr[$key]);\n}\nvar_dump($arr);<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code>array(4) { [0]=&gt; int(1) [1]=&gt; int(2) [3]=&gt; int(4) [4]=&gt; int(5) }<\/code><\/pre>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u53ef\u4ee5\u770b\u5230\u4f7f\u7528array_splice()\u5220\u9664\u7279\u5b9a\u503c\u548c\u4f7f\u7528unset\u5220\u9664\u7279\u5b9a\u503c\u662f\u6709\u533a\u522b\u7684\u3002<\/p>\n<p>array_splice()\u51fd\u6570\u5220\u9664\u7684\u8bdd\uff0c\u6570\u7ec4\u7684\u7d22\u5f15\u503c\u4e5f\u4ea7\u751f\u53d8\u5316\u3002<\/p>\n<p>unset()\u51fd\u6570\u5220\u9664\u7684\u8bdd\uff0c\u6570\u7ec4\u7684\u7d22\u5f15\u503c\u6ca1\u6709\u53d8\u5316\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>array_splice \u4ee3\u7801\u5982\u4e0b\uff1a $arr = array(1, 2, 3, 4, 5); $key =  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-php-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}