I had a script not exactly the same as what you want.. But it got names.. And it got everyones name and matched them next to each other.. There wasnt any that were the same so no..
mac n mac etc..
But basically what i did was
Have each name in an array
So for you
a and a
have array
$array = array("a","b");
From there you''ll need to have a foreach statement.. Then another in it. In the second foreach you'd display the data.. If i ever find the script.. Ill show you exactly what i did.