{"id":512,"date":"2020-04-11T00:45:00","date_gmt":"2020-04-11T04:45:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=512"},"modified":"2021-01-02T00:46:21","modified_gmt":"2021-01-02T05:46:21","slug":"php-how-to-access-last-element-in-an-array","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/php-how-to-access-last-element-in-an-array\/","title":{"rendered":"PHP: How to access last element in an array"},"content":{"rendered":"\n<p>Since PHP array are indexed from 0, the last element at any given time has the index count of array minus one. Following is a code example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ accessing last element in an array\n$a = array('adam', 'bob', 'cathy');\nprint $a&#91;count($a) - 1];<\/code><\/pre>\n\n\n\n<p>The output of this code is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cathy<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Since PHP array are indexed from 0, the last element at any given time has the index count of array minus one. Following is a code example: The output of this code is:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[24],"class_list":["post-512","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":513,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/512\/revisions\/513"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}