{"id":70,"date":"2024-05-29T17:25:40","date_gmt":"2024-05-29T17:25:40","guid":{"rendered":"https:\/\/codingindialab.com\/blog\/?p=70"},"modified":"2026-04-06T05:00:05","modified_gmt":"2026-04-06T05:00:05","slug":"remove-the-duplicate-words-in-two-different-strings-using-php","status":"publish","type":"post","link":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/","title":{"rendered":"Remove duplicate string in PHP"},"content":{"rendered":"<h2>Let&#8217;s See How We Can Make This?<\/h2>\n<p>You need to create a function to remove the word from two different strings, You can name the function as you like. We are used <strong>removeCommonWords<\/strong> to built this.<\/p>\n<p>We will create two different variables in which we will pass the words and this function will give you the same word after removing it as you can see in the example given below:<\/p>\n<p><strong>Example Code:<\/strong><\/p>\n<p>&lt;?php<br \/>\nfunction removeCommonWords($string1, $string2) {<br \/>\n$array1 = explode(&#8216; &#8216;, $string1);<br \/>\n$array2 = explode(&#8216; &#8216;, $string2);<br \/>\n\/\/ Find common words and remove them from both arrays<br \/>\n$commonWords = array_intersect($array1, $array2);<br \/>\n$array1 = array_diff($array1, $commonWords);<br \/>\n$array2 = array_diff($array2, $commonWords);<br \/>\n\/\/ Reconstruct strings<br \/>\n$newString1 = implode(&#8216; &#8216;, $array1);<br \/>\n$newString2 = implode(&#8216; &#8216;, $array2);<br \/>\nreturn [$newString1, $newString2];<br \/>\n}<br \/>\n\/\/ Example usage<br \/>\n$string1 = &#8220;Testing&#8221;;<br \/>\n$string2 = &#8220;Testing Data&#8221;;<br \/>\nlist($newString1, $newString2) = removeCommonWords($string1, $string2);<br \/>\necho &#8220;String 2 without common words: $newString2\\n&#8221;;<br \/>\n?&gt;<\/p>\n<h2>Copy<\/h2>\n<p>Use the above code for you upcoming product. This is very useful when we want to remove the same words from the different string.<\/p>\n<h2>Why We Use Remove The Duplicate Words In Two Different Strings ?<\/h2>\n<p>When we work with backend functionality like <strong>MYSQLI <\/strong>and retrieve the data and don&#8217;t want to show the duplicate word, Then we can use the function to remove the duplicate words.<\/p>\n<p>You can also use this function to remove the same heading in two different sentences.<\/p>\n<h2>What is Important of Remove Duplicate words from the Two String<\/h2>\n<ul>\n<li><strong>Date cleanness : <\/strong>If the text in the database is duplicated, Then we are unable to read it properly, Which makes it very difficult to read. If we clean up the duplicate data, So it will be easier for us to read it.<\/li>\n<li><strong>Improved Readability: <\/strong>If the text is not duplicate or unnecessary then it becomes easier to read and can be understood easily.<\/li>\n<li><strong>Better User Experience:\u00a0<\/strong>If repeated words are removed then it will be easier for the user to read<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s See How We Can Make This? You need to create a function to remove&#8230;<\/p>\n","protected":false},"author":1,"featured_media":228,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Remove duplicate string in PHP<\/title>\n<meta name=\"description\" content=\"How to remove duplicate words\/repeated words from the two different string. We have added example for this just copy and paste the code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remove duplicate string in PHP\" \/>\n<meta property=\"og:description\" content=\"How to remove duplicate words\/repeated words from the two different string. We have added example for this just copy and paste the code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Buy Tools - Coding India Lab\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-29T17:25:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-06T05:00:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/#\\\/schema\\\/person\\\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce\"},\"headline\":\"Remove duplicate string in PHP\",\"datePublished\":\"2024-05-29T17:25:40+00:00\",\"dateModified\":\"2026-04-06T05:00:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/\"},\"wordCount\":322,\"image\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/codingindialab.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1\",\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/\",\"url\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/\",\"name\":\"Remove duplicate string in PHP\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/codingindialab.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1\",\"datePublished\":\"2024-05-29T17:25:40+00:00\",\"dateModified\":\"2026-04-06T05:00:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/#\\\/schema\\\/person\\\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce\"},\"description\":\"How to remove duplicate words\\\/repeated words from the two different string. We have added example for this just copy and paste the code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/codingindialab.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/codingindialab.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1\",\"width\":1920,\"height\":500,\"caption\":\"Remove duplicate string in PHP\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/remove-the-duplicate-words-in-two-different-strings-using-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Remove duplicate string in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/\",\"name\":\"Coding India\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/#\\\/schema\\\/person\\\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/codingindialab.com\\\/blog\"],\"url\":\"https:\\\/\\\/codingindialab.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Remove duplicate string in PHP","description":"How to remove duplicate words\/repeated words from the two different string. We have added example for this just copy and paste the code.","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:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Remove duplicate string in PHP","og_description":"How to remove duplicate words\/repeated words from the two different string. We have added example for this just copy and paste the code.","og_url":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/","og_site_name":"Buy Tools - Coding India Lab","article_published_time":"2024-05-29T17:25:40+00:00","article_modified_time":"2026-04-06T05:00:05+00:00","og_image":[{"width":1920,"height":500,"url":"https:\/\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp","type":"image\/webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#article","isPartOf":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/"},"author":{"name":"admin","@id":"https:\/\/codingindialab.com\/blog\/#\/schema\/person\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce"},"headline":"Remove duplicate string in PHP","datePublished":"2024-05-29T17:25:40+00:00","dateModified":"2026-04-06T05:00:05+00:00","mainEntityOfPage":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/"},"wordCount":322,"image":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1","articleSection":["php"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/","url":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/","name":"Remove duplicate string in PHP","isPartOf":{"@id":"https:\/\/codingindialab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#primaryimage"},"image":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1","datePublished":"2024-05-29T17:25:40+00:00","dateModified":"2026-04-06T05:00:05+00:00","author":{"@id":"https:\/\/codingindialab.com\/blog\/#\/schema\/person\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce"},"description":"How to remove duplicate words\/repeated words from the two different string. We have added example for this just copy and paste the code.","breadcrumb":{"@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#primaryimage","url":"https:\/\/i0.wp.com\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1","contentUrl":"https:\/\/i0.wp.com\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1","width":1920,"height":500,"caption":"Remove duplicate string in PHP"},{"@type":"BreadcrumbList","@id":"https:\/\/codingindialab.com\/blog\/remove-the-duplicate-words-in-two-different-strings-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codingindialab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Remove duplicate string in PHP"}]},{"@type":"WebSite","@id":"https:\/\/codingindialab.com\/blog\/#website","url":"https:\/\/codingindialab.com\/blog\/","name":"Coding India","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codingindialab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codingindialab.com\/blog\/#\/schema\/person\/94a2d1f0e37a9a178ed9cd0a3aa7f3ce","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd5a9365f6d133d34466f8b64e07682be41ad59e15e64b8bda642df41823202e?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codingindialab.com\/blog"],"url":"https:\/\/codingindialab.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/codingindialab.com\/blog\/wp-content\/uploads\/2024\/05\/remove-the-duplicate-words-1.webp?fit=1920%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":1,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions\/229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/media\/228"}],"wp:attachment":[{"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingindialab.com\/blog\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}