{"id":382,"date":"2022-10-27T07:55:25","date_gmt":"2022-10-27T07:55:25","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=382"},"modified":"2022-10-28T07:14:54","modified_gmt":"2022-10-28T07:14:54","slug":"how-to-check-a-key-exist-in-array-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/","title":{"rendered":"How to check a key exist in array? Explain with example?"},"content":{"rendered":"\n<p>We can check a key exist or not in an array with the help of <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">array_key_exist() <\/mark>function in PHP.                      <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">array_key_exists<\/mark>() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist, &nbsp;if we skip the key when we specify an array, an integer key is generated which starts at 0 and increases by 1 for each value.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">syntax<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array_key_exists(key, array)<\/code><\/pre>\n\n\n\n<p><strong>this function takes two argument and this function returns boolean values(TRUE\/FALSE), nested keys always return false value.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"413\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\" alt=\"\" class=\"wp-image-465\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png 823w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists-300x151.png 300w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists-768x385.png 768w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">example1<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n       <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"> \/\/ with key values<\/mark>\n\t\t$shivam = array(\"shivam\" =&gt; \"23\",\"ravi\" =&gt; \"24\",\"abhi\" =&gt; \"25\");\n\t\t\n\t\t\tif (array_key_exists(\"abhi\",$shivam))\n\t\t\t{\n\t\t\t\techo \"Key exists\";\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\techo \"Key not exist\";\n\t\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>Key exists<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">example 2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n      <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\"> \/\/ with no key values<\/mark>\n\t\t$shivam = array(\"shivam\",\"ravi\",\"abhi\");\n\t\t\n\t\t\tif (array_key_exists(0,$shivam))\n\t\t\t{\n\t\t\t\techo \"Key exists\";\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\techo \"Key not exist\";\n\t\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>Key exists<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We can check a key exist or not in an array with the help of array_key_exist() function in PHP. array_key_exists() function checks an array for a specified key, and returns&hellip;<\/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-382","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to check a key exist in 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-check-a-key-exist-in-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 check a key exist in array? Explain with example? - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"We can check a key exist or not in an array with the help of array_key_exist() function in PHP. array_key_exists() function checks an array for a specified key, and returns&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T07:55:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-28T07:14:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\" \/>\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-check-a-key-exist-in-array-explain-with-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\"},\"author\":{\"name\":\"shivam\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53\"},\"headline\":\"How to check a key exist in array? Explain with example?\",\"datePublished\":\"2022-10-27T07:55:25+00:00\",\"dateModified\":\"2022-10-28T07:14:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\"},\"wordCount\":107,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\",\"url\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\",\"name\":\"How to check a key exist in array? Explain with example? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\",\"datePublished\":\"2022-10-27T07:55:25+00:00\",\"dateModified\":\"2022-10-28T07:14:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage\",\"url\":\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\",\"contentUrl\":\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png\",\"width\":823,\"height\":413},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-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 check a key exist in 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\/0c8259479972d3d18994f88df3dc8d53\",\"name\":\"shivam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/image\/\",\"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 check a key exist in 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-check-a-key-exist-in-array-explain-with-example\/","og_locale":"en_US","og_type":"article","og_title":"How to check a key exist in array? Explain with example? - DevOps | SRE | DevSecOps","og_description":"We can check a key exist or not in an array with the help of array_key_exist() function in PHP. array_key_exists() function checks an array for a specified key, and returns&hellip;","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T07:55:25+00:00","article_modified_time":"2022-10-28T07:14:54+00:00","og_image":[{"url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png","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-check-a-key-exist-in-array-explain-with-example\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/"},"author":{"name":"shivam","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"headline":"How to check a key exist in array? Explain with example?","datePublished":"2022-10-27T07:55:25+00:00","dateModified":"2022-10-28T07:14:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/"},"wordCount":107,"commentCount":0,"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/","name":"How to check a key exist in array? Explain with example? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage"},"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png","datePublished":"2022-10-27T07:55:25+00:00","dateModified":"2022-10-28T07:14:54+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-array-explain-with-example\/#primaryimage","url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png","contentUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array_key_exists.png","width":823,"height":413},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-check-a-key-exist-in-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 check a key exist in 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\/0c8259479972d3d18994f88df3dc8d53","name":"shivam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/image\/","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\/382","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=382"}],"version-history":[{"count":4,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":466,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions\/466"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}