I need the same functionality of R function make.unique in PHP.
In R:
> dup_array = c("a", "b", "a", "c")
> make.unique(dup_array)
[1] "a" "b" "a.1" "c"
In PHP:
> dup_array = array("a", "b", "a", "c")
> magic_function(dup_array)
What is the magic_function
?
2
Answers
You could do it like this:
You can test it:
And results in:
Well, there are no in-built functions already for this as yet, however, you can create your own custom function for it.
Keep track of current frequency of the element using a dictionary(associative array) and then attach the current frequency accordingly.
Online Demo