Hello.
halojoy here.
There are like 10 functions in PHP that can sort an array.
In different ways.
I hope you can advice me what to use in this case.
But also we can discuss some other cases dealing with Sorting Arrays.
Can be very useful to know, as a row, record, from database
most likely turns up as An Array of some kind.
<?php
// Original data
// name, age, location, email
$data[0] = array( 'billy', 33, 'UK', 'billy@londontown.com' );
$data[1] = array( 'sally', 74, 'Germany', 'sally@yahoo.com' );
$data[2] = array( 'ronny', 17, 'USA', 'ronny@google.com' );
$data[3] = array( 'tim', 50, 'Singapore', 'tim@hotmail.com' );
// Most simple way to do this task below?
// Must be several ways to re-sort this data array.
// Several php functions can do same thing.
// Give me 2-3 different solutions
// I am sure persons would come up with own different way to do this
// But one has to be best one! The one I will use.
// Question 1: How to sort this array after column 'age'?
// Result order should be: 17-33-50-74
$data[0] = array( 'ronny', 17, 'USA', 'ronny@google.com' );
$data[1] = array( 'billy', 33, 'UK', 'billy@londontown.com' );
$data[2] = array( 'tim', 50, 'Singapore', 'tim@hotmail.com' );
$data[3] = array( 'sally', 74, 'Germany', 'sally@yahoo.com' );
// Question 2: How to sort by email provider?
// Result order should be: google-hotmail-londontown-yahoo
$data[0] = array( 'ronny', 17, 'USA', 'ronny@google.com' );
$data[1] = array( 'tim', 50, 'Singapore', 'tim@hotmail.com' );
$data[2] = array( 'billy', 33, 'UK', 'billy@londontown.com' );
$data[3] = array( 'sally', 74, 'Germany', 'sally@yahoo.com' );
// Question 3/4: How to sort like 1 and 2, but with reverse order?
// Result order should be, age: 74-50-33-17
// Result order should be, email: yahoo-londontown-hotmail-google
// Thanks for your help. Next time I help you.
// /halojoy July 2005 Sweden
?>