Sorting an array in different ways with efficient output
There isn't much to say about your code, it's pretty good. You avoided duplication by extracting code to functions, and your code is pretty clean in general.

Some nitpicks:


echo"&lt;br&gt;";: you are missing a space here
your array would also be more readable with an extra space after , and spaces around =&gt;. Putting each array value on it's own line will increase readability even more (the extra space it takes up is well worth it).
your echo needs to be indented a bit more.
$p and $a could be $person and $age for more clarity.


Reviewing code not written by you is off-topic, so I'll be brief about that. But yes, you are right with all your questions. There is a lot of duplication in that code (the duplicate arrays might be explained by them wanting to sort the exact same array each time, instead of one that has already been changed by another sort function; in that case, a getPerson function would avoid duplication), the formatting is pretty bad (unnecessary newlines, no paragraphs, no indentation, lack of spaces, etc), multiple statements on one line, and so on.