I query a database in PHP which will get results like the following table. These are stored in an associative array.
What I now want to be able to do is select only the records by a certain work_type
and return the same type of associative array
. For example "Part Time"
. Then I want to be able to sort these records according to whatever column I decide. How would I do this?
This is as far as I got...
$data = $_SESSION['results']; //the database query results
foreach($data as $key => $row)
{
if(in_array($row['work_type'], array('Part Time')))
{
$type[$key] = $row['work_type'];
$date_posted[$key] = $row['created_at'];
}
}
array_multisort($type, SORT_ASC, $date_posted, SORT_ASC, $data);
This doesn't work because the $data array which I send to multi-sort
is a now different size to the ones I created.