I find myself arranging an arrangement and I must order it by two of its fields in this case 'ppu' and 'sense'.
Achievement regroup it by ppu, but I can not do it for both.
Example of the arrangement
Array
(
[id] => 1
[num] => 1
[ppu] => ZJ1805
[sTs] => 126
[sUsuario] => 126
[sentido] => Ida
[periodo] => FPMA
[estrato] => B
[uNegocio] => U1
[cParada] => T-14-125-NS-5
[cUsuario] => PC38
[comuna] => PROVIDENCIA
[eje] => MANUEL MONTT
[desde] => AV. NUEVA PROVIDENCIA
[hacia] => GRANADEROS
[nParada] => Parada 5 / (M) Manuel Montt
[zPaga] => 18:00 - 20:00
[uValidan] => 11
[uEvaden1] => 0
[uEvaden2] => 0
[uEvaden3] => 0
[uEvaden4] => 0
)
The code I'm using for this is:
<?php
$enlace = mysqli_connect("localhost", "root", "", "db_evasion");
if (!$enlace) {
echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
echo "error de depuración: " . mysqli_connect_errno() . PHP_EOL;
echo "error de depuración: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$query = "SELECT * FROM medicion";
$resultados = mysqli_query($enlace, $query);
$newArray = array();
while ($resultado = mysqli_fetch_assoc($resultados)) {
$newArray[] = $resultado;
}
$result = array();
foreach ($newArray as $data) {
$ppu = $data['ppu'];
$sentido = $data['sentido'];
if (isset($result[$ppu]) && isset($result[$sentido])) {
$result[$ppu][] = $data;
} else {
$result[$ppu] = array($data);
}
}
pre($result);
exit;
?>
This makes me sort by ppu, but I can not group by 2 criteria.