{"id":368,"date":"2022-10-27T06:15:37","date_gmt":"2022-10-27T06:15:37","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=368"},"modified":"2022-10-28T07:44:10","modified_gmt":"2022-10-28T07:44:10","slug":"how-to-create-an-empty-array-in-php-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/","title":{"rendered":"How to create an empty array in PHP? Explain with example?"},"content":{"rendered":"\n<p>array() function is use to create an array in our PHP and php supports three types of array-<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>index array= it has index values<\/li><li>associative array= it has string keys<\/li><li>multidimensional array= it contains one or more array in particular array<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">&nbsp;Why it is always good practice to declare an empty array and then push the items to that array?<\/h4>\n\n\n\n<p>when declare an empty array and then start entering elements in it later. with the help of this, it can prevent different errors due to a faulty array. it helps to have the information of using bugged, rather having the array. it saves time during the debugging. Most of the time it may not have anything to add to the array at the point of creation.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Syntax<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$emptyArray = &#91;];\n      or\n$emptyArray = array();\n\n       or\n$emptyArray = (array) null;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\" alt=\"\" class=\"wp-image-481\" width=\"602\" height=\"339\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp 602w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca-300x169.webp 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><figcaption><strong>EMPTY ARRAY<\/strong><\/figcaption><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">example<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n\t\t$subjects = array();\n\t\tif (count($subjects) == 0)\n\t\t{\n\t\t\t\techo \" the array is empty\";\n\t\t}\n\t\telse\n\t\t{\n\t\t    echo \"array is not empty\";\n\t\t}\n\t\t\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">output<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>the array is empty<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>array() function is use to create an array in our PHP and php supports three types of array- index array= it has index values associative array= it&#8230; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create an empty array in PHP? 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-create-an-empty-array-in-php-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 create an empty array in PHP? Explain with example? - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"array() function is use to create an array in our PHP and php supports three types of array- index array= it has index values associative array= it...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T06:15:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-28T07:44:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\" \/>\n<meta name=\"author\" content=\"shivam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shivam\" \/>\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-create-an-empty-array-in-php-explain-with-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/\"},\"author\":{\"name\":\"shivam\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"headline\":\"How to create an empty array in PHP? Explain with example?\",\"datePublished\":\"2022-10-27T06:15:37+00:00\",\"dateModified\":\"2022-10-28T07:44:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/\"},\"wordCount\":143,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/\",\"name\":\"How to create an empty array in PHP? Explain with example? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\",\"datePublished\":\"2022-10-27T06:15:37+00:00\",\"dateModified\":\"2022-10-28T07:44:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\",\"contentUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp\",\"width\":602,\"height\":339},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create an empty array in PHP? 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\\\/0c8259479972d3d18994f88df3dc8d53\",\"name\":\"shivam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"caption\":\"shivam\"},\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/author\\\/shivam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create an empty array in PHP? 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-create-an-empty-array-in-php-explain-with-example\/","og_locale":"en_US","og_type":"article","og_title":"How to create an empty array in PHP? Explain with example? - DevOps | SRE | DevSecOps","og_description":"array() function is use to create an array in our PHP and php supports three types of array- index array= it has index values associative array= it...","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T06:15:37+00:00","article_modified_time":"2022-10-28T07:44:10+00:00","og_image":[{"url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp","type":"","width":"","height":""}],"author":"shivam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shivam","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/"},"author":{"name":"shivam","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"headline":"How to create an empty array in PHP? Explain with example?","datePublished":"2022-10-27T06:15:37+00:00","dateModified":"2022-10-28T07:44:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/"},"wordCount":143,"commentCount":0,"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/","name":"How to create an empty array in PHP? Explain with example? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#primaryimage"},"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp","datePublished":"2022-10-27T06:15:37+00:00","dateModified":"2022-10-28T07:44:10+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#primaryimage","url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp","contentUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/main-qimg-5d56c9f979e2eddb85472af4d6245fca.webp","width":602,"height":339},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to create an empty array in PHP? 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\/0c8259479972d3d18994f88df3dc8d53","name":"shivam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","caption":"shivam"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/shivam\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/368","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":3,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":485,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions\/485"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}