{"id":2186,"date":"2013-02-06T13:46:30","date_gmt":"2013-02-06T13:46:30","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=2186"},"modified":"2013-02-06T13:46:30","modified_gmt":"2013-02-06T13:46:30","slug":"php-remove-last-array-element-how-to-remove-last-array-item-in-php","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/php-remove-last-array-element-how-to-remove-last-array-item-in-php\/","title":{"rendered":"Using PHP To Remove Last Array Element \/ Item"},"content":{"rendered":"<p>Once again, we come back to Arrays. In the previous article, we have seen how important it could be remove first array item. Now it would be really helpful \u00a0to find out how to remove last array item using PHP. In this article, I am going to share very easy way to use <em><strong>PHP to\u00a0remove last array element<\/strong><\/em> by making use of easy to follow examples. So read on to find out more.<!--more--><\/p>\n<h2>How to use PHP to Remove Last Array Element \/ Item<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2186\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Let&#8217;s assume that we an array in PHP, that contains the fruit names. So in this example, we will see how to remove the last item from this fruits array.<\/p>\n<h3>Example: Remove last element from an array using PHP<\/h3>\n<pre class=\"lang:xhtml decode:true\" title=\"Example\">&lt;?php \n\/\/Declare an empty array\n$my_fruits_array = array('apple', 'mango', 'grapes', 'pineapple');\n\n\/\/Print the contents of the array. Use the &lt;pre&gt; tags to output the array in readable format.\necho 'Following are the original array contents:&lt;br \/&gt;';\necho '&lt;pre&gt;';\nprint_r($my_fruits_array);\necho '&lt;\/pre&gt;';\n\n\/\/Remove Last Element From Array Using PHP\narray_pop($my_fruits_array);\n\n\/\/Print the contents of the array. Use the &lt;pre&gt; tags to output the array in readable format.\necho 'Following are the array contents AFTER removing the last item from array:&lt;br \/&gt;';\necho '&lt;pre&gt;';\nprint_r($my_fruits_array);\necho '&lt;\/pre&gt;';\n?&gt;<\/pre>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=2186\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p><strong>Simple, isn&#8217;t it?<\/strong><\/p>\n<p>Do you know of any other ways to use <strong><em>PHP to\u00a0remove last array element<\/em><\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once again, we come back to Arrays. In the previous article, we have seen how important it could be remove first array item. Now it would be really helpful \u00a0to find out how to remove last array item using PHP. In this article, I am going to share very easy way to use PHP to\u00a0remove [&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":[10,13],"tags":[125,33],"class_list":["post-2186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tips-and-tricks","category-tips-and-tricks","tag-php-demos-2","tag-php-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-zg","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2186","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=2186"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/2186\/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=2186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=2186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=2186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}