{"id":1990,"date":"2013-01-21T13:47:06","date_gmt":"2013-01-21T13:47:06","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1990"},"modified":"2013-01-21T13:47:06","modified_gmt":"2013-01-21T13:47:06","slug":"php-remove-from-array-php-delete-from-array-delete-remove-array-element","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-remove-from-array-php-delete-from-array-delete-remove-array-element\/","title":{"rendered":"PHP Delete \/ Remove From Array Examples"},"content":{"rendered":"<p>A very important concept in PHP is the arrays. So if you are familiar with it, you may have come across a situation where you wanted to <strong>use PHP to remove element from array<\/strong>. So do you know how to delete a specific element from array? If not, this article is for you. In this article, I am going to share with you a very easy way to r<strong>emove or delete element from array<\/strong>. So read on to find out more.<\/p>\n<p><!--more--><\/p>\n<h2>Use PHP to Remove Element From Array &#8211; Examples<\/h2>\n<p>Let&#8217;s take a look at <strong>how to remove element from array<\/strong> by using an easy to follow example. Let&#8217;s consider that we have an array of fruits &amp; we have a vegetable ( an array item ) that we would like to delete from the array. We are going to look at two ways to <strong>delete the array item.<\/strong> The first way would be to <strong>use the index of the array element to remove the array element<\/strong>\u00a0directly. The second way is to <strong>use specified key to remove the array item<\/strong>.<\/p>\n<h3>Example 1: Use Index to Remove Array element using PHP<\/h3>\n<pre class=\"lang:php decode:true\" title=\"Example 1\">&lt;?php \n$fruits = array('apple', 'mango', 'grapes', 'pineapple', 'potato');\n\n\/\/Using index to remove array element\nunset( $fruits[4] );\n\necho '&lt;pre&gt;Result after Using index to remove array element&lt;br \/&gt;';\nprint_r($fruits);\necho '&lt;\/pre&gt;';\n\n\/\/Output\nArray\n(\n&amp;nbsp; &amp;nbsp; [0] =&gt; apple\n&amp;nbsp; &amp;nbsp; [1] =&gt; mango\n&amp;nbsp; &amp;nbsp; [2] =&gt; grapes\n&amp;nbsp; &amp;nbsp; [3] =&gt; pineapple\n)\n?&gt;<\/pre>\n<h3>Example 2: Use specified key to delete array element using PHP<\/h3>\n<pre class=\"lang:xhtml decode:true crayon-selected\" title=\"Example 2\">&lt;?php\n\/\/Using the specified key to delete array element\n$fruits = array('fruit1' =&gt; 'apple', 'fruit2' =&gt; 'mango', 'fruit3' =&gt; 'grapes', 'fruit4' =&gt; 'pineapple', 'fruit5' =&gt; 'potato');\n\nunset( $fruits['fruit5'] );\n\necho '&lt;pre&gt;Result after Using specified key to delete array element&lt;br \/&gt;';\nprint_r($fruits);\necho '&lt;\/pre&gt;';\n\n\/\/Output\nArray\n(\n    [fruit1] =&gt; apple\n    [fruit2] =&gt; mango\n    [fruit3] =&gt; grapes\n    [fruit4] =&gt; pineapple\n)\n?&gt;<\/pre>\n<p><strong>Simple, isn&#8217;t it?<\/strong><br \/>\nDo you know of any other ways to <strong>remove element from array using PHP<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A very important concept in PHP is the arrays. So if you are familiar with it, you may have come across a situation where you wanted to use PHP to remove element from array. So do you know how to delete a specific element from array? If not, this article is for you. In this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":141,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13],"tags":[33],"class_list":["post-1990","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-w6","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1990"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1990\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}