Note that there are some explanatory texts on larger screens.

plurals
  1. POphp count the values between 2 intervals in foreach loop
    primarykey
    data
    text
    <p>I have the following array :</p> <pre><code> Array ( [0] =&gt; Array ( [serial_number] =&gt; 00127B4EE68F [start_log_date] =&gt; 00:34:28 [log_date] =&gt; 00:36:52 [good_files] =&gt; 11 [bad_files] =&gt; 0 [interrupted_files] =&gt; 0 [skipped_door_files] =&gt; 0 [max_rate] =&gt; 560.52 [min_rate] =&gt; 215.59 [avg_rate] =&gt; 360.54 [total_bytes_before_transfer] =&gt; 40598530 [total_bytes_after_transfer] =&gt; 0 [firmware] =&gt; 10.6 ) [1] =&gt; Array ( [serial_number] =&gt; 00127B4F0F98 [start_log_date] =&gt; 00:59:55 [log_date] =&gt; 01:00:21 [good_files] =&gt; 1 [bad_files] =&gt; 0 [interrupted_files] =&gt; 0 [skipped_door_files] =&gt; 0 [max_rate] =&gt; [min_rate] =&gt; [avg_rate] =&gt; [total_bytes_before_transfer] =&gt; 2276 [total_bytes_after_transfer] =&gt; 0 [firmware] =&gt; 10.6 ) [2] =&gt; Array ( [serial_number] =&gt; 00127B4F0F97 [start_log_date] =&gt; 01:00:59 [log_date] =&gt; 01:01:55 [good_files] =&gt; 4 [bad_files] =&gt; 0 [interrupted_files] =&gt; 0 [skipped_door_files] =&gt; 0 [max_rate] =&gt; 557.7 [min_rate] =&gt; 334.16 [avg_rate] =&gt; 397.21 [total_bytes_before_transfer] =&gt; 11979855 [total_bytes_after_transfer] =&gt; 0 [firmware] =&gt; 10.6 ) [3] =&gt; Array ( [serial_number] =&gt; 00127B4ED82D [start_log_date] =&gt; 01:08:10 [log_date] =&gt; 01:08:35 [good_files] =&gt; 1 [bad_files] =&gt; 0 [interrupted_files] =&gt; 0 [skipped_door_files] =&gt; 0 [max_rate] =&gt; [min_rate] =&gt; [avg_rate] =&gt; [total_bytes_before_transfer] =&gt; 234 [total_bytes_after_transfer] =&gt; 0 [firmware] =&gt; 10.6 ) [4] =&gt; Array ( [serial_number] =&gt; 00127B4EE61D [start_log_date] =&gt; 01:54:51 [log_date] =&gt; 01:55:17 [good_files] =&gt; 1 [bad_files] =&gt; 0 [interrupted_files] =&gt; 0 [skipped_door_files] =&gt; 0 [max_rate] =&gt; [min_rate] =&gt; [avg_rate] =&gt; [total_bytes_before_transfer] =&gt; 68136 [total_bytes_after_transfer] =&gt; 0 [firmware] =&gt; 10.6 ) ) </code></pre> <p>I want to check if the value from <code>log_date</code> is smaller than the next <code>start_log_date</code>. If it's smaller, make a count and continue. I made a <code>foreach</code> loop but I don't get the result I want.</p> <p>This is how I want to display the results (example):</p> <pre><code>Simultaneous connections: 2 - from 03:38:55 PM to 04:51:10 PM - ( 1h 12 min ) 1 serial number start_log_date log_date 2 serial number start_log_date log_date Simultaneous connections: 1 - from 03:38:55 PM to 03:40:10 PM - ( 1 min ) 1 serial number start log date log_date etc... </code></pre> <p>This is my initial loop:</p> <pre><code> $iCount = 1; $i = 0; foreach($aRecordsPerDay as $key=&gt;$aRow) { $aTimeStart[] = strtotime($aRow["start_log_date"]); $aTimeStopOld[] = strtotime($sTimeStopOld); if(strtotime($aRow['start_log_date']) &lt; max($aTimeStopOld)) { $sTimeStart = $aTimeStart[$i-$iCount]; $sTimeStop = $aRow['log_date']; if(strtotime($sTimeStop) &lt; strtotime($sTimeStopOld)) $sTimeStop = $sTimeStopOld; $aTimeStop[] = strtotime($sTimeStop); $iCount+=1; } else { if($iCount &gt; 1) { echo "Simultaneous connections".$iCount; $iCount = 1; } else { echo "Simultaneous connections 1"; $iCount = 1; } } $sTimeStartOld=$aRow['start_log_date']; $sTimeStopOld=$aRow['log_date']; $i++; ///show data } </code></pre> <p>and this is the result I get:</p> <pre><code> 1 serial number start_log_date log_date 2 serial number start_log_date log_date Simultaneous connections: 2 - from 03:38:55 PM to 04:51:10 PM - ( 1h 12 min ) 1 serial number start log date log_date Simultaneous connections: 1 - from 03:38:55 PM to 03:40:10 PM - ( 1 min ) etc.. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload