В настоящее время у меня есть массив информации о местоположении, подобной ниже (которая уже отсортирована по времени). Первый ключ / значение – это событие, которое представляет собой начало путешествия (00), путешествие (01) и конец путешествия (10).
Array ( [0] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [1] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [2] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [3] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [4] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [5] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [6] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [7] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [8] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [9] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [10] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [11] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [12] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [13] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [14] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [15] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [16] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [17] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [18] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) )
Как я могу разделить массив еще дальше, чтобы он создавал новый массив для каждого путешествия, поэтому я в итоге получаю следующее:
Array ( [0] => Array ( [0] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [1] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [2] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [3] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [4] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [5] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) ) [1] => Array ( [0] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [1] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [2] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [3] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [4] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [5] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [6] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [7] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) ) ... )
Я еще ничего не пробовал (за исключением googling), поскольку я не знаю, с чего начать.
вам нужно индивидуальное решение:
$outputArray = array(); $currentArray = array(); foreach($inputArray as $key=>$subArray) { if($subArray['event']==00) { $outputArray[] = $currentArray; $currentArray = array($subArray); } else { $currentArray[] = $subArray; } } $outputArray[] = $currentArray; array_shift($outputArray);
введите $ inputArray, а затем выйдите из $ outputArray. Наслаждайтесь!
попробуй это:
$journey = array ( [0] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [1] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [2] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [3] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [4] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [5] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [6] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [7] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [8] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [9] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [10] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [11] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [12] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [13] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [14] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [15] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [16] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [17] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [18] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) ) $journeygrouping = array(); while(!empty($journey)){ $temp = array_pop($journey); if(isset($journeygrouping[$temp['event']])){ array_push($journeygrouping[$temp['event']], $temp); } else { $journeygrouping[$temp['event']] = array(); array_push($journeygrouping[$temp['event']], $temp); } }
в$journey = array ( [0] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [1] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [2] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [3] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [4] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [5] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [6] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [7] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [8] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [9] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [10] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [11] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [12] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [13] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [14] => Array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [15] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [16] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [17] => Array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) [18] => Array ( [event] => 10 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 ) ) $journeygrouping = array(); while(!empty($journey)){ $temp = array_pop($journey); if(isset($journeygrouping[$temp['event']])){ array_push($journeygrouping[$temp['event']], $temp); } else { $journeygrouping[$temp['event']] = array(); array_push($journeygrouping[$temp['event']], $temp); } }
этот код должен создать структуру массива, такую как:
array( [00] => array([0] => array([event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111) [1]=>array ( [event] => 00 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111 )) [01] => array([0]=>array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111) [1]=>array ( [event] => 01 [time] => 1329293878 [lat] => 66.66666 [lon] => 11.11111) ) );
и так далее…