- print_r: documentation ( source)
- array_shift: documentation ( source)
- array_keys: documentation ( source)
<?php
$array = array('name', 'name', 'email', 'name', 'address', 'phone', 'phone');
foreach ($array as $value) {
$keys = array_keys($array, $value);
// get rid of the first entry
array_shift($keys);
// add counters to duplicates
for ($i = 0; $i < count($keys); $i++) {
$array[$keys[$i]] = $value . "_" . ($i + 2);
}
}
print_r($array);