{"id":400,"date":"2022-10-27T09:59:30","date_gmt":"2022-10-27T09:59:30","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=400"},"modified":"2022-10-27T10:00:21","modified_gmt":"2022-10-27T10:00:21","slug":"how-to-create-an-empty-array-in-php-explain-with-example-2","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/","title":{"rendered":"How to create an empty array in PHP? explain with example"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>You may ask, \u201c<strong>How to create an empty array in PHP?<\/strong>\u201d This is common in PHP codes, where you may want to store the values of a future computation into an array. You basically would declare the array as empty and store the computed values into it.<\/p>\n\n\n\n<p>So, how can this be achieved?<\/p>\n\n\n\n<p>PHP arrays with no value can be initialized in three ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\uff04myArray = array();<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>\uff04myArray = [];<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>\uff04myArray = (array) null;<\/li><\/ul>\n\n\n\n<p>Among the three methods shown, the most common among programmers is the second, which uses [].<br>This is because the second method is marginally faster as it is only a constructor and is just simpler to use.<\/p>\n\n\n\n<p>Code<\/p>\n\n\n\n<p>Let\u2019s check out some code that uses the techniques listed above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  \n$empty1 = (array) null;\n$empty2 = &#91;];\n$empty3 = array();\nvar_dump($empty1,$empty2,$empty3);\n\n\/\/All above array are empty and will return empty\n\/\/pushing values into second type of array\n$empty&#91;]  =\"traps\" ;\n$empty&#91;]  =\"tracks\" ;\n$empty&#91;]  =\"traces\" ;\n$empty&#91;]  =\"traps\" ;\nvar_dump ($empty) ;\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You may ask, \u201cHow to create an empty array in PHP?\u201d This is common in PHP codes, where you may want to store the values of a&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-400","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-2\/\" \/>\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=\"You may ask, \u201cHow to create an empty array in PHP?\u201d This is common in PHP codes, where you may want to store the values of a...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T09:59:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-27T10:00:21+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-create-an-empty-array-in-php-explain-with-example-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/\"},\"author\":{\"name\":\"rahulkr kr\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"headline\":\"How to create an empty array in PHP? explain with example\",\"datePublished\":\"2022-10-27T09:59:30+00:00\",\"dateModified\":\"2022-10-27T10:00:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/\"},\"wordCount\":130,\"commentCount\":0,\"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-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/\",\"name\":\"How to create an empty array in PHP? explain with example - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"datePublished\":\"2022-10-27T09:59:30+00:00\",\"dateModified\":\"2022-10-27T10:00:21+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-empty-array-in-php-explain-with-example-2\\\/#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\\\/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 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-2\/","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":"You may ask, \u201cHow to create an empty array in PHP?\u201d This is common in PHP codes, where you may want to store the values of a...","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T09:59:30+00:00","article_modified_time":"2022-10-27T10:00:21+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-create-an-empty-array-in-php-explain-with-example-2\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/"},"author":{"name":"rahulkr kr","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"headline":"How to create an empty array in PHP? explain with example","datePublished":"2022-10-27T09:59:30+00:00","dateModified":"2022-10-27T10:00:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/"},"wordCount":130,"commentCount":0,"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-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/","name":"How to create an empty array in PHP? explain with example - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"datePublished":"2022-10-27T09:59:30+00:00","dateModified":"2022-10-27T10:00:21+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-empty-array-in-php-explain-with-example-2\/#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\/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\/400","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=400"}],"version-history":[{"count":3,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/400\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/400\/revisions\/405"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}