I need help sorting [Time]
data from in this array in php. For a given day, the time is NOT in order.
Is there a way to sort this? Thanks.
Array ( [0] => Array ( )
[1] => Array (
[Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db2.bak_lvm
[Time] => 06:00:02
[Duration] => 01:28:12
[Size] => 72.05 GB
[Status] => Succeeded )
[2] => Array ( [Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db2.bak_lvm
[Time] => 00:00:03
[Duration] => 01:49:37
[Size] => 187.24 GB
[Status] => Succeeded )
[3] => Array ( [Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db3.bak_lvm
[Time] => 23:00:03
[Status] => Unsuccessful )
[4] => Array ( [Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db4.bak_lvm
[Time] => 04:00:03
[Duration] => 00:42:36
[Size] => 46.46 GB
[Status] => Succeeded )
Here's my php code, thus far:
<?php
$data = array();
$InputFile = file("test.txt");
foreach ($InputFile as $line){
preg_match_all("/([0-9])-([^=]+)=([^;]+);/", $line, $matches, PREG_SET_ORDER);
$LineData = array();
foreach ($matches as $information)
$LineData[$information[2]] = $information[3];
$data[] = $LineData;
}
$keys = array('Server', 'Date','Set','Time','Duration','Size','Status');
echo '<table id="stats"><tr>';
foreach ($keys as $column)
echo '<th>' . $column . '</th>';
echo '</tr>';
$counter=0;
foreach ($data as $row){
$counter ++;
$class = $counter % 2 === 0 ? 'alt1' : 'alt2';
echo '<tr class="' . $class . '">';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column];
} else {
echo '<td>' . '' . '</td>';
}
}
echo '</table>';
print_r($data);
?>
Updated: Latest sort after using suggested fix by Bill. [Time]
is in order, but also need to have it sorted within [Date]
Array ( [0] => Array (
[Server] => server1.name
[Date] => Mon Aug 23 2010
[Set] => db2.bak_lvm
[Time] => 00:00:03
[Duration] => 01:50:24
[Size] => 187.24 GB
[Status] => Succeeded )
[1] => Array ( [Server] => server1.name
[Date] => Mon Aug 23 2010
[Set] => db3.bak_lvm
[Time] => 04:00:02
[Duration] => 00:42:28
[Size] => 46.47 GB
[Status] => Succeeded )
[2] => Array ( [Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db3.bak_lvm
[Time] => 04:00:03
[Duration] => 00:42:36
[Size] => 46.46 GB
[Status] => Succeeded )
[3] => Array ( [Server] => server1.name
[Date] => Mon Aug 23 2010
[Set] => db1.bak_lvm
[Time] => 06:00:02
[Duration] => 01:28:24
[Size] => 72.05 GB
[Status] => Succeeded )
[4] => Array ( [Server] => server1.name
[Date] => Sun Aug 22 2010
[Set] => db4.bak_lvm
[Time] => 20:00:03
[Duration] => 04:17:57
[Size] => 426.60 GB
[Status] => Succeeded )