Well, what you probably really should do is have a relational table set-up where there is only one ID per row. I'm not real sure what you're trying to do, but I suspect it would be something like:
user_id
friend_user_id
timestamp
Then your query would be something like:
SELECT friend_user_id FROM table_name WHERE user_id="$userid" ORDER BY timestamp DESC LIMIT 24
But, if you're stuck working from an exploded array, you could get the last 24 entries via:
for($ix = 0; $ix < 24 and count($array); $ix++)
{
echo "<p>" . array_pop($array) . "</p>\n";
}