bubbles Posted May 28, 2015 Report Posted May 28, 2015 Salut,Am un array de genul : Array( [0] => Array ( [0] => YES [1] => 2015-05-01 ) [1] => Array ( [0] => YES [1] => 2015-05-02 ) [2] => Array ( [0] => YES [1] => 2015-05-03 ) [3] => Array ( [0] => YES [1] => 2015-05-04 ) [4] => Array ( [0] => YES [1] => 2015-05-05 ) [5] => Array ( [0] => YES [1] => 2015-05-06 ) [6] => Array ( [0] => NO [1] => 2015-05-07 ) [7] => Array ( [0] => YES [1] => 2015-05-08 ) [8] => Array ( [0] => NO [1] => 2015-05-09 ) [9] => Array ( [0] => YES [1] => 2015-05-10 ) [10] => Array ( [0] => YES [1] => 2015-05-11 ) [11] => Array ( [0] => YES [1] => 2015-05-12 ) [12] => Array ( [0] => NO [1] => 2015-05-13 ) [13] => Array ( [0] => YES [1] => 2015-05-14 ) [14] => Array ( [0] => NO [1] => 2015-05-15 ) [15] => Array ( [0] => YES [1] => 2015-05-16 ) [16] => Array ( [0] => YES [1] => 2015-05-17 ) [17] => Array ( [0] => NO [1] => 2015-05-18 ) [18] => Array ( [0] => YES [1] => 2015-05-19 ) [19] => Array ( [0] => YES [1] => 2015-05-20 ) [20] => Array ( [0] => YES [1] => 2015-05-21 ) [21] => Array ( [0] => NO [1] => 2015-05-22 ) [22] => Array ( [0] => NO [1] => 2015-05-23 ) [23] => Array ( [0] => NO [1] => 2015-05-24 ) [24] => Array ( [0] => NO [1] => 2015-05-25 ) [25] => Array ( [0] => YES [1] => 2015-05-26 ) [26] => Array ( [0] => YES [1] => 2015-05-27 ))Si as vrea sa aflu YES de cate ori a aparut cel mai mult CONSECUTIV si implicit data de start/end.Daca e sa fac manual YES a aparut consecutiv cel mai mult de 6 ori perioada (2015-05-01 / 2015-05-06).O idee ? Merci. Quote
caii Posted May 28, 2015 Report Posted May 28, 2015 Nu am testat, dar este o idee$stats = array(); //aici tii numaratoarea$stats['count'] = 0;$stats['count_old'] = 0;foreach($array as $data)//$array este arrayul tau{ if($data[0] == 'YES') { if($stats['count'] == 0) $stats['start'] = $data[1]; //la primul YES adaugi 'start' $stats['end'] = $data[1]; //de fiecare data cand apare YES updatezi 'end' $stats['count']++; //de cate ori apare YES } else { if($stats['count'] > $stats['count_old']) //mentii maximul de YES consecutive in 'count_old' { $stats['start_old'] = $stats['start']; $stats['end_old'] = $stats['end']; $stats['count_old'] = $stats['count']; } $stats['count'] = 0; }}//iti mai trebuie un if in caz ca $stats['count'] iti da mai mare decat $stats['count_old'] cand se termina foreach Quote
Wav3 Posted June 2, 2015 Report Posted June 2, 2015 $max = array();$last_max = array();foreach ($ARR as $i=>$v) { if ($v[0] == "Yes") { $max['start'] = ($max['count'] == 0) ? $v[1] : $max['start']; $max['count']++; if ($max['count'] > $last_max['count']) { $last_max['count'] = $max['count']; $last_max['start'] = $max['start']; $last_max['end'] = $v[1]; } } else { $max['count'] = 0; }}ah, am scris acelasi lucru, cailor. Quote
Axu Posted June 2, 2015 Report Posted June 2, 2015 Am si eu o intrebare:Ce vrea @bubbles, se poate realiza si prin query in db? Daca da, cum ar arata? Quote
EAdrian Posted June 2, 2015 Report Posted June 2, 2015 (edited) Why not PHP: array_count_values - Manual ?Am si eu o intrebare:Ce vrea @bubbles, se poate realiza si prin query in db? Daca da, cum ar arata?SELECT COUNT(*) FROM `table` WHERE `column` = 'YES' Edited June 2, 2015 by EAdrian Quote