{"id":512,"date":"2022-11-01T11:55:55","date_gmt":"2022-11-01T11:55:55","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=512"},"modified":"2022-11-01T11:55:55","modified_gmt":"2022-11-01T11:55:55","slug":"how-to-remove-duplicate-values-from-php-array-explain-with-example-2","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/","title":{"rendered":"How to remove duplicate values from PHP Array? explain with example"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg\" alt=\"\" class=\"wp-image-513\" width=\"732\" height=\"366\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg 1024w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array-300x150.jpg 300w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array-768x384.jpg 768w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><figcaption><strong><em>Remove Duplicate Elements from the Array<\/em><\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>In this query, we will discuss How to remove duplicate elements from an array in PHP. We can get the unique elements by using array_unique() function. This function will remove the duplicate values from the array.<\/p>\n\n\n\n<p>Parameters: This function accepts two parameters that are discussed below:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>$array:<\/strong> This parameter is mandatory to be supplied and it specifies the input array from which we want to remove duplicates.<\/li><li><strong>$sort_flags<\/strong>: It is an optional parameter. This parameter may be used to modify the sorting behavior using these values:<\/li><li><strong>SORT_REGULAR:<\/strong> This is the default value of the parameter $sort_flags. This value tells the function to compare items normally (don\u2019t change types).<\/li><li><strong>SORT_NUMERIC<\/strong>: This value tells the function to compare items numerically.<\/li><li><strong>SORT_STRING:<\/strong> This value tells the function to compare items as strings.<\/li><li><strong>SORT_LOCALE_STRING:<\/strong> This value tells the function to compare items as strings, based on the current locale.<\/li><li><strong>Return Value:<\/strong> The array_unique() function returns the filtered value after removing all duplicates from the array.<\/li><\/ul>\n\n\n\n<p>Example: PHP program to remove duplicate values from the array.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Input Array\r\n$a = array(\"circle\", \"square\", \"circle\", \"triangle\");\r\n  \r\n\/\/ Array after removing duplicates\r\nprint_r(array_unique($a));\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<br>Array<br>(<br>[0] =&gt; circle<br>[1] =&gt; square<br>[3] =&gt; triangle<br>)<\/p>\n\n\n\n<p>Example: PHP program to remove duplicate elements from an associative array.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Input array\r\n$arr = array(\r\n      \"a\" => \"BH\", \r\n      \"b\" => \"CK\", \r\n      \"c\" => \"CK\", \r\n      \"d\" => \"AND\"\r\n);\r\n  \r\n\/\/ Array after removing duplicates\r\nprint_r(array_unique($arr));\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<br>Array<br>(<br>[a] =&gt; BH<br>[b] =&gt; CK<br>[d] =&gt; AND<br>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this query, we will discuss How to remove duplicate elements from an array in PHP. We can get the unique elements by using array_unique() function. This&#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,165,113,193],"tags":[209,210,208,211,212,214,215],"class_list":["post-512","post","type-post","status-publish","format-standard","hentry","category-array","category-function","category-php","category-php-array","tag-array_unique-function","tag-remove-duplicate-elements-from-an-associative-array","tag-remove-duplicate-values-from-php","tag-remove-duplicate-values-from-the-array","tag-sort_locale_string","tag-sort_numeric","tag-sort_string"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to remove duplicate values from PHP 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-remove-duplicate-values-from-php-array-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 remove duplicate values from PHP Array? explain with example - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"In this query, we will discuss How to remove duplicate elements from an array in PHP. We can get the unique elements by using array_unique() function. This...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-01T11:55:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg\" \/>\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-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/\"},\"author\":{\"name\":\"rahulkr kr\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"headline\":\"How to remove duplicate values from PHP Array? explain with example\",\"datePublished\":\"2022-11-01T11:55:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/\"},\"wordCount\":226,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/remove-duplicate-elements-from-array.jpg\",\"keywords\":[\"array_unique() function\",\"remove duplicate elements from an associative array\",\"remove duplicate values from PHP\",\"remove duplicate values from the array\",\"sort_locale_string\",\"sort_numeric\",\"sort_string\"],\"articleSection\":[\"Array\",\"Function\",\"PHP\",\"PHP Array\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/\",\"name\":\"How to remove duplicate values from PHP Array? explain with example - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/remove-duplicate-elements-from-array.jpg\",\"datePublished\":\"2022-11-01T11:55:55+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/remove-duplicate-elements-from-array.jpg\",\"contentUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/remove-duplicate-elements-from-array.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-remove-duplicate-values-from-php-array-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 remove duplicate values from PHP 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 remove duplicate values from PHP 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-remove-duplicate-values-from-php-array-explain-with-example-2\/","og_locale":"en_US","og_type":"article","og_title":"How to remove duplicate values from PHP Array? explain with example - DevOps | SRE | DevSecOps","og_description":"In this query, we will discuss How to remove duplicate elements from an array in PHP. We can get the unique elements by using array_unique() function. This...","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-11-01T11:55:55+00:00","og_image":[{"url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg","type":"","width":"","height":""}],"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-remove-duplicate-values-from-php-array-explain-with-example-2\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/"},"author":{"name":"rahulkr kr","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"headline":"How to remove duplicate values from PHP Array? explain with example","datePublished":"2022-11-01T11:55:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/"},"wordCount":226,"commentCount":0,"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg","keywords":["array_unique() function","remove duplicate elements from an associative array","remove duplicate values from PHP","remove duplicate values from the array","sort_locale_string","sort_numeric","sort_string"],"articleSection":["Array","Function","PHP","PHP Array"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/","name":"How to remove duplicate values from PHP Array? explain with example - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#primaryimage"},"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg","datePublished":"2022-11-01T11:55:55+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-explain-with-example-2\/#primaryimage","url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg","contentUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/11\/remove-duplicate-elements-from-array.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-remove-duplicate-values-from-php-array-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 remove duplicate values from PHP 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\/512","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=512"}],"version-history":[{"count":2,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":515,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions\/515"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}