{"id":4582,"date":"2022-08-04T06:46:30","date_gmt":"2022-08-04T06:46:30","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4582"},"modified":"2022-08-04T06:46:30","modified_gmt":"2022-08-04T06:46:30","slug":"what-is-the-use-of-count-function-in-php","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/","title":{"rendered":"What is the use of count () function in PHP ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">In PHP this unbuilt function is used to count the current elements in the array.<\/li>\n<li style=\"text-align: justify;\">If it has been set to an empty array, whether the function might return 0 for the variable and the variable that is not set the function returns 0.<\/li>\n<li style=\"text-align: justify;\">Generally, this function takes one parameter, the array for which the elements need to be counted.<\/li>\n<li style=\"text-align: justify;\">The function an take a parameter <i>mode which<\/i>\u00a0tells the function to count the element in recursive or normal mode but in addition.<\/li>\n<li style=\"text-align: justify;\">In Count () syntax $array is mandatory and in which elements are needed to be counted.<\/li>\n<li style=\"text-align: justify;\">In Count () mode is optional which is used to set the mode of function and their parameter can take two possible values, either 0 or 1. 1 generally indicates to count of the values of the array recursively.<\/li>\n<li style=\"text-align: justify;\">In an array, the functions return the number of elements.<\/li>\n<\/ul>\n<h2 id=\"syntax\" style=\"text-align: justify;\">Syntax<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">Count ($array, mode)<\/code><\/pre> <\/div>\n<h2 id=\"sample-code\" style=\"text-align: justify;\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\"><!DOCTYPE html><br\/>  <html><br\/>   <body><br\/><br\/>     <?php<br\/>       $cars=array(&quot;Volvo&quot;,&quot;Volkswagen&quot;,&quot;Hyundai&quot;,&quot;Ferrari&quot;);<br\/>       echo count($cars);<br\/>       ?><br\/><br\/>   <\/body><br\/><\/html><\/code><\/pre> <\/div>\n<h2 id=\"output\" style=\"text-align: justify;\">Output<\/h2>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4583\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png\" alt=\"\" width=\"1118\" height=\"208\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png 1118w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php-300x56.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php-1024x191.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php-768x143.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php-390x73.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php-820x153.png 820w\" sizes=\"(max-width: 1118px) 100vw, 1118px\" \/><\/p>\n<p style=\"text-align: justify;\">\n","protected":false},"excerpt":{"rendered":"<p>In PHP this unbuilt function is used to count the current elements in the array. If it has been set to an empty array, whether the function might return 0 for the variable and the variable that is not set the function returns 0. Generally, this function takes one parameter, the array for which the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8182],"tags":[17790,17789,17782,17787,17784,17786,17788,17781,17783,17785],"class_list":["post-4582","post","type-post","status-publish","format-standard","hentry","category-php","tag-array-count","tag-array_count_values-in-php","tag-count-function-in-php","tag-count-function-in-php-mysql","tag-how-to-count-all-elements-in-an-array-in-php","tag-php-array-count-example","tag-php-count-with-condition","tag-php-count-function","tag-php-count-function-with-examples","tag-what-is-the-use-of-count-function-in-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is the use of count () function in PHP ? - PHP Count() Function<\/title>\n<meta name=\"description\" content=\"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0\" \/>\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.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the use of count () function in PHP ? - PHP Count() Function\" \/>\n<meta property=\"og:description\" content=\"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-04T06:46:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\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.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/\"},\"author\":{\"name\":\"webmaster\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"headline\":\"What is the use of count () function in PHP ?\",\"datePublished\":\"2022-08-04T06:46:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/\"},\"wordCount\":217,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/count-function-in-php.png\",\"keywords\":[\"array count\",\"array_count_values in php\",\"count() function in php\",\"count() function in php mysql\",\"how to count all elements in an array in php\",\"php array count example\",\"php count with condition\",\"php count() function\",\"php count() function with examples\",\"what is the use of count function in php\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/\",\"name\":\"What is the use of count () function in PHP ? - PHP Count() Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/count-function-in-php.png\",\"datePublished\":\"2022-08-04T06:46:30+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/php\\\/what-is-the-use-of-count-function-in-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/count-function-in-php.png\",\"contentUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/count-function-in-php.png\",\"width\":1118,\"height\":208},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\"],\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/webmaster\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the use of count () function in PHP ? - PHP Count() Function","description":"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0","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.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/","og_locale":"en_US","og_type":"article","og_title":"What is the use of count () function in PHP ? - PHP Count() Function","og_description":"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/","og_site_name":"Wikitechy","article_published_time":"2022-08-04T06:46:30+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png","type":"","width":"","height":""}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/"},"author":{"name":"webmaster","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"headline":"What is the use of count () function in PHP ?","datePublished":"2022-08-04T06:46:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/"},"wordCount":217,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png","keywords":["array count","array_count_values in php","count() function in php","count() function in php mysql","how to count all elements in an array in php","php array count example","php count with condition","php count() function","php count() function with examples","what is the use of count function in php"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/","name":"What is the use of count () function in PHP ? - PHP Count() Function","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png","datePublished":"2022-08-04T06:46:30+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is the use of count () function in PHP ? - In PHP this unbuilt function is used to count the current elements in the array.\u00a0","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-is-the-use-of-count-function-in-php\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/count-function-in-php.png","width":1118,"height":208},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4582"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4582\/revisions"}],"predecessor-version":[{"id":4584,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4582\/revisions\/4584"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}