3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
30.49 ms | 402 KiB | 5 Q