PHP Array Exercises : Sort a specified array by the day and username
22. Sort Array by Day and Username
Write a PHP script to sort the following array by the day (page_id) and username.
Sample Solution:
PHP Code:
Output:
$arra[0]: 2025731450 user_name: Illiya $arra[1]: 2025731470 user_name: Sana $arra[2]: 1025731456 user_name: Robin $arra[3]: 1025731460 user_name: Samantha
Flowchart:

For more Practice: Solve these Related Problems:
- Write a PHP script to sort a multi-dimensional array by two keys: first by day (page_id) and then by username in ascending order.
- Write a PHP function that accepts an array containing day and username fields and outputs the sorted array based on both keys.
- Write a PHP program to group an array by day and then sort the groups alphabetically by username.
- Write a PHP script to combine sorting functions to order a multi-dimensional array by day first and then by username using a custom comparison callback.
Go to:
PREV : Sort Subnets.
NEXT : Sort Multi-Dimensional Array by Specific Key.
PHP Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.