{"id":406,"date":"2022-10-27T10:31:39","date_gmt":"2022-10-27T10:31:39","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=406"},"modified":"2022-10-27T10:31:39","modified_gmt":"2022-10-27T10:31:39","slug":"how-to-get-a-number-of-elements-in-an-array-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/","title":{"rendered":"How to get a number of elements in an Array? explain with example"},"content":{"rendered":"\n<p>In this query, we will discuss how to get number of elements in an array. We can get total number of elements in an array by using count() and sizeof() functions.<br><strong>Using count() Function<\/strong>: The count() function is used to get the total number of elements in an array.<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  count(array)<\/code><\/pre>\n\n\n\n<p>Parameters: It accepts a single parameter i.e. array which is the input array.<\/p>\n\n\n\n<p>Return Value: It returns the number of elements in an array.<\/p>\n\n\n\n<p>Program : PHP program to count elements in an array using count() function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Create an associative array \r\n\/\/ with 5 subjects\r\n$array1 = array(\r\n      0 => 'php',  \r\n      1 => 'Laravel',  \r\n      2 => 'Bootstrap', \r\n      3 => 'python',\r\n      4 => 'C++'\r\n);\r\n  \r\n\/\/ Get total elements in array\r\necho count( $array1);\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p><strong>sizeof() Function<\/strong>: The sizeof() function is used to count the number of elements present in an array or any other countable object.<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<p>sizeof(array)<br>Parameters: It accepts only one parameter array which is the input array.<\/p>\n\n\n\n<p>Return Value: It returns the number of elements present in an array.<\/p>\n\n\n\n<p>Examples:<\/p>\n\n\n\n<p><strong>Input<\/strong>: array(10,20,30,50)<br><strong>Output<\/strong>: 4<\/p>\n\n\n\n<p><strong>Input<\/strong>: array(&#8220;Hello&#8221;,&#8221;geeks&#8221;)<br><strong>Output<\/strong>: 2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Create an associative array\r\n\/\/ with 5 subjects\r\n$array1 = array(\r\n      0 => 'php',  \r\n    1 =>'Laravel',  \r\n      2 => 'Bootstrap', \r\n      3 => 'python',\r\n      4 => 'C++'\r\n);\r\n  \r\n\/\/ Get total elements in array\r\necho sizeof( $array1);\r\n  \r\n?><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this query, we will discuss how to get number of elements in an array. We can get total number of elements in an array by using&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,113],"tags":[164,163,161,158,160,162],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-array","category-php","tag-array-using-count-function","tag-create-an-associative-array","tag-input-array","tag-number-of-elements-in-an-array","tag-php-program","tag-total-elements-in-array"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"In this query, we will discuss how to get number of elements in an array. We can get total number of elements in an array by using...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T10:31:39+00:00\" \/>\n<meta name=\"author\" content=\"rahulkr kr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rahulkr kr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/\"},\"author\":{\"name\":\"rahulkr kr\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"headline\":\"How to get a number of elements in an Array? explain with example\",\"datePublished\":\"2022-10-27T10:31:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/\"},\"wordCount\":158,\"commentCount\":0,\"keywords\":[\"array using count() function\",\"Create an associative array\",\"input array\",\"number of elements in an Array\",\"PHP program\",\"total elements in array\"],\"articleSection\":[\"Array\",\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/\",\"name\":\"How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"datePublished\":\"2022-10-27T10:31:39+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get a number of elements in an Array? explain with example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\",\"name\":\"DevOps | SRE | DevSecOps\",\"description\":\"Automation means Cost, Quality, Time\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\",\"name\":\"rahulkr kr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"caption\":\"rahulkr kr\"},\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/author\\\/rahulkr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/","og_locale":"en_US","og_type":"article","og_title":"How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps","og_description":"In this query, we will discuss how to get number of elements in an array. We can get total number of elements in an array by using...","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T10:31:39+00:00","author":"rahulkr kr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rahulkr kr","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/"},"author":{"name":"rahulkr kr","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"headline":"How to get a number of elements in an Array? explain with example","datePublished":"2022-10-27T10:31:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/"},"wordCount":158,"commentCount":0,"keywords":["array using count() function","Create an associative array","input array","number of elements in an Array","PHP program","total elements in array"],"articleSection":["Array","PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/","name":"How to get a number of elements in an Array? explain with example - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"datePublished":"2022-10-27T10:31:39+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-get-a-number-of-elements-in-an-array-explain-with-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get a number of elements in an Array? explain with example"}]},{"@type":"WebSite","@id":"https:\/\/www.devopstrainer.in\/blog\/#website","url":"https:\/\/www.devopstrainer.in\/blog\/","name":"DevOps | SRE | DevSecOps","description":"Automation means Cost, Quality, Time","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopstrainer.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d","name":"rahulkr kr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","caption":"rahulkr kr"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/rahulkr\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=406"}],"version-history":[{"count":5,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":415,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/406\/revisions\/415"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}