What are some alternative approaches to sorting and displaying user statistics based on points in a PHP application?
When sorting and displaying user statistics based on points in a PHP application, one alternative approach is to use the `usort()` function to sort the user statistics array based on points. This function allows for custom sorting logic to be implemented. Once the array is sorted, it can be displayed in the desired format.
// Sample user statistics array
$userStatistics = [
['name' => 'Alice', 'points' => 100],
['name' => 'Bob', 'points' => 75],
['name' => 'Charlie', 'points' => 120],
];
// Custom sorting function based on points
usort($userStatistics, function($a, $b) {
return $a['points'] < $b['points'];
});
// Display sorted user statistics
foreach ($userStatistics as $user) {
echo $user['name'] . ' - Points: ' . $user['points'] . PHP_EOL;
}