so all double entries need to become one (like if you've got twice Peter,80.0.0.1 in the array) and all the different names with the same ip need to be ordered like the above array

How to do this? :/ I've tried so many things now, but can't seem to find the right way. I don't really want a double for-loop to sort everything, there must be a smarter way to do this...
anybody can figure out a script to solve my problem?