How to Create ?
You need to create a function to hide the word from two different strings, You can name the function as you like.
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:
Example Code:
<?php
function hideCommonWords($string1, $string2) {
$array1 = explode(‘ ‘, $string1);
$array2 = explode(‘ ‘, $string2);
// Find common words and remove them from both arrays
$commonWords = array_intersect($array1, $array2);
$array1 = array_diff($array1, $commonWords);
$array2 = array_diff($array2, $commonWords);
// Reconstruct strings
$newString1 = implode(‘ ‘, $array1);
$newString2 = implode(‘ ‘, $array2);
return [$newString1, $newString2];
}
// Example usage
$string1 = “Bajaj”;
$string2 = “Bajaj Dominar 250”;
list($newString1, $newString2) = hideCommonWords($string1, $string2);
echo “String 2 without common words: $newString2\n”;
?>