I have a text say:
$text = "An Elephant is an Elephant but an Elephant is not an Elephant"
And I have an array say:
$array = array("First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eight", "Ninth");
In the text you can see there are many occurrences of "Elephant". What I want to do is I want to replace the occurrences of Elephant with unique values from the array and the result should be something like this:
$result = "An Fifth is an Seventh but an First is not an Fourth"
I have tried this so far :
$arr = array("First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eight", "Ninth");
$text = "an elephant is an elephant but an elephant is not an elephant";
$array = explode(" ", $text);
$new_arr = array_diff($array, array("elephant"));
$text = implode(" ".$arr[array_rand($arr)]." ", $new_arr);
echo $text;
It outputs something like this:
an First is First an First but First an First is First not First an
How can I get like this?
An Fifth is an Seventh but an First is not an Fourth