複数のオカレンスがある場合、配列内のすべての文字列の後に -1、-2... を追加する必要があると思います。このコードを確認してください:
<?php
$array = array("this", "is", "my", "string", "and", "it", "is", "a", "string", "do", "you", "like", "my", "string");
$ocurrences = array();
$iterator = new ArrayIterator($array);
while ($iterator->valid()) {
$keys = array_keys($ocurrences);
if (in_array($iterator->current(), $keys)) {
$array[$iterator->key()] = $iterator->current() . '-' . $ocurrences[$iterator->current()];
$ocurrences[$iterator->current()]++;
}
else {
$ocurrences[$iterator->current()] = 1;
}
$iterator->next();
}
print_r($array);
それは印刷されます:
Array
(
[0] => this
[1] => is
[2] => my
[3] => string
[4] => and
[5] => it
[6] => is-1
[7] => a
[8] => string-1
[9] => do
[10] => you
[11] => like
[12] => my-1
[13] => string-2
)