Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak "przefiltrować" tablicę ?
tomzoll
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 19.09.2011

Ostrzeżenie: (0%)
-----


Witam serdecznie. Zmagam się z takim tematem i nie mogę sobie poradzić (IMG:style_emoticons/default/sad.gif)
Mianowicie jest taka sytuacja:
Mam tablicę w której skład wchodzą elementy: Latitude, Longitude, StartTime, StopTime, Numer. Wartości wpisów sobie pogrupowałem wg elementu "Numer". Chciałbym osiągnąć taki efekt aby na podstawie źródłowej tablicy utworzyć nową tablicę która będzie zawierać pola:
1. Jeśli w tablicy źródłowej jest jeden wpis z danym 'Numerem' to należy go przepisać do nowej tablicy
2. Jeśli w tablicy źródłowej jest więcej niż jeden wpis z taką samą wartością pola 'Numer' to należy w nowej tablicy utworzyć nowy element, zawierający pola 'Latitude', 'Longitude', 'StartTime' z wartościami z pierwszego w kolejności wpisu z danym 'Numerem' i jednocześnie z polem 'StopTime' o wartości z ostatniego napotkanego wpisu z tym samym 'Numerem'.
Jednym słowem chciałbym aby z tej źródłowej tablicy:
Kod
array(23) {
  [0]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5766784"
    ["Longitude"]=>
    string(9) "2.2192276"
    ["StartTime"]=>
    string(19) "2015-10-01 08:02:18"
    ["StopTime"]=>
    string(19) "2015-10-01 08:05:18"
    ["Numer"]=>
    int(2)
  }

  [1]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5767616"
    ["Longitude"]=>
    string(9) "2.2194676"
    ["StartTime"]=>
    string(19) "2015-10-01 08:28:02"
    ["StopTime"]=>
    string(19) "2015-10-01 08:29:02"
    ["Numer"]=>
    int(33)
  }
  [2]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5767616"
    ["Longitude"]=>
    string(9) "2.2194676"
    ["StartTime"]=>
    string(19) "2015-10-01 08:29:02"
    ["StopTime"]=>
    string(19) "2015-10-01 08:31:50"
    ["Numer"]=>
    int(33)
  }
  [3]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5767616"
    ["Longitude"]=>
    string(9) "2.2194676"
    ["StartTime"]=>
    string(19) "2015-10-01 08:31:50"
    ["StopTime"]=>
    string(19) "2015-10-01 08:31:51"
    ["Numer"]=>
    int(33)
  }


uzyskać taką tablicę:
Kod
array(23) {
  [0]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5766784"
    ["Longitude"]=>
    string(9) "2.2192276"
    ["StartTime"]=>
    string(19) "2015-10-01 08:02:18"
    ["StopTime"]=>
    string(19) "2015-10-01 08:05:18"
    ["Numer"]=>
    int(2)
  }

  [1]=>
  array(5) {
    ["Latitude"]=>
    string(10) "41.5767616"
    ["Longitude"]=>
    string(9) "2.2194676"
    ["StartTime"]=>
    string(19) "2015-10-01 08:28:02"
    ["StopTime"]=>
    string(19) "2015-10-01 08:31:51"
    ["Numer"]=>
    int(33)
  }



Z góry dziękuję za pomoc.
Poniżej fragment tablicy.
Pozdrawiam (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.09.2025 - 16:11