php - How to remove unnecessary rows from multidimensional array? -


i have fingerprint records this

"our company";"100";"100";07/25/2017 5:02:57 pm;"check out";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 7:45:53 am;"check in";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 7:45:54 am;"check in";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 6:01:34 pm;"check out";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 6:01:35 pm;"check out";"1";"";0;"fingerpint";"" "our company";"104";"104";07/25/2017 8:00:06 am;"check out";"1";"";0;"fingerpint";"" "our company";"104";"104";07/25/2017 5:35:19 pm;"check in";"1";"";0;"fingerpint";"" "our company";"105";"105";07/25/2017 8:47:37 am;"check in";"1";"";0;"fingerpint";"" "our company";"108";"108";07/25/2017 8:45:42 am;"check in";"1";"";0;"fingerpint";"" "our company";"108";"108";07/25/2017 6:04:00 pm;"check out";"1";"";0;"fingerpint";"" "our company";"11";"11";07/25/2017 8:57:34 am;"check in";"1";"";0;"fingerpint";"" "our company";"11";"11";07/25/2017 5:12:06 pm;"check out";"1";"";0;"fingerpint";"" "our company";"112";"112";07/25/2017 8:43:56 am;"check in";"1";"";0;"password";"" "our company";"112";"112";07/25/2017 5:39:26 pm;"check out";"1";"";0;"password";"" "our company";"112";"112";07/25/2017 5:41:17 pm;"check out";"1";"";0;"password";"" 

formatted:

array (     [0] => array         (             [0] => "our company"             [1] => "100"             [2] => "100"             [3] => 07/25/2017 5:02:57 pm             [4] => "check out"             [5] => "1"             [6] => ""             [7] => 0             [8] => "fingerpint"             [9] => ""         )      [1] => array         (             [0] => "our company"             [1] => "102"             [2] => "102"             [3] => 07/25/2017 7:45:53             [4] => "check in"             [5] => "1"             [6] => ""             [7] => 0             [8] => "fingerpint"             [9] => ""         )      [2] => array         (             [0] => "our company"             [1] => "102"             [2] => "102"             [3] => 07/25/2017 7:45:54             [4] => "check in"             [5] => "1"             [6] => ""             [7] => 0             [8] => "fingerpint"             [9] => ""         )     ... ) 

and want first record each check in , check out. record contains multiple entries each id id 102 has 2 check ins , 2 check outs.i want first record check in , first record check out. here approach.

while (($data = fgetcsv($handle, 1000, ";")) !== false) {         $num = count($data);         ($c=0; $c < $num; $c++) {             if ($c == 1 || $c == 2 || $c == 3 || $c == 4) {                 if($d != 0){                     $dtary[$d][$c] = $data[$c] ;                 }             }             if ($c == 9 ) {                 $d++ ;             }         }     } 

how set condition?

is expected result?

"our company";"100";"100";07/25/2017 5:02:57 pm;"check out";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 7:45:53 am;"check in";"1";"";0;"fingerpint";"" "our company";"102";"102";07/25/2017 6:01:34 pm;"check out";"1";"";0;"fingerpint";"" "our company";"104";"104";07/25/2017 8:00:06 am;"check out";"1";"";0;"fingerpint";"" "our company";"104";"104";07/25/2017 5:35:19 pm;"check in";"1";"";0;"fingerpint";"" "our company";"105";"105";07/25/2017 8:47:37 am;"check in";"1";"";0;"fingerpint";"" "our company";"108";"108";07/25/2017 8:45:42 am;"check in";"1";"";0;"fingerpint";"" "our company";"108";"108";07/25/2017 6:04:00 pm;"check out";"1";"";0;"fingerpint";"" "our company";"11";"11";07/25/2017 8:57:34 am;"check in";"1";"";0;"fingerpint";"" "our company";"11";"11";07/25/2017 5:12:06 pm;"check out";"1";"";0;"fingerpint";"" "our company";"112";"112";07/25/2017 8:43:56 am;"check in";"1";"";0;"password";"" "our company";"112";"112";07/25/2017 5:39:26 pm;"check out";"1";"";0;"password";"" 

you should try array_intersect.

if constraint id , 'check in/out' without considering datetime or unique check in/out per day, check out:

<?php  $myarray = array(); $myarray[] = array("our company","100","100","07/25/2017 5:02:57 pm","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","102","102","07/25/2017 7:45:53 am","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","102","102","07/25/2017 7:45:54 am","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","102","102","07/25/2017 6:01:34 pm","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","102","102","07/25/2017 6:01:35 pm","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","104","104","07/25/2017 8:00:06 am","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","104","104","07/25/2017 5:35:19 pm","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","105","105","07/25/2017 8:47:37 am","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","108","108","07/25/2017 8:45:42 am","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","108","108","07/25/2017 6:04:00 pm","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","11","11","07/25/2017 8:57:34 am","check in","1","",0,"fingerpint",""); $myarray[] = array("our company","11","11","07/25/2017 5:12:06 pm","check out","1","",0,"fingerpint",""); $myarray[] = array("our company","112","112","07/25/2017 8:43:56 am","check in","1","",0,"password",""); $myarray[] = array("our company","112","112","07/25/2017 5:39:26 pm","check out","1","",0,"password",""); $myarray[] = array("our company","112","112","07/25/2017 5:41:17 pm","check out","1","",0,"password","");   /**  * compare 2 arrays , return true if intersected counts same.  */  function in_array_intersect ($target, $haystack) {     foreach ($haystack $item) {         if ( (count(array_intersect(array($item[1], $item[4]), $target)) == count($target))) {             return true;         }     }     return false; }  // define new array hold matched records $resultarray = array();  foreach ($myarray $subarray) {     // create new array 2 columns, id , checkin/out     $target = array($subarray[1], $subarray[4]);         if (!in_array_intersect($target, $resultarray)){         // add $subarray $resultarray if no array found in $resultarray matching columns constraint         array_push($resultarray, $subarray);     }    }  echo '<pre>'; print_r($resultarray); echo '</pre>';  ?> 

result:

array (     [0] => array         (             [0] => our company             [1] => 100             [2] => 100             [3] => 07/25/2017 5:02:57 pm             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [1] => array         (             [0] => our company             [1] => 102             [2] => 102             [3] => 07/25/2017 7:45:53             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [2] => array         (             [0] => our company             [1] => 102             [2] => 102             [3] => 07/25/2017 6:01:34 pm             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [3] => array         (             [0] => our company             [1] => 104             [2] => 104             [3] => 07/25/2017 8:00:06             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [4] => array         (             [0] => our company             [1] => 104             [2] => 104             [3] => 07/25/2017 5:35:19 pm             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [5] => array         (             [0] => our company             [1] => 105             [2] => 105             [3] => 07/25/2017 8:47:37             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [6] => array         (             [0] => our company             [1] => 108             [2] => 108             [3] => 07/25/2017 8:45:42             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [7] => array         (             [0] => our company             [1] => 108             [2] => 108             [3] => 07/25/2017 6:04:00 pm             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [8] => array         (             [0] => our company             [1] => 11             [2] => 11             [3] => 07/25/2017 8:57:34             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [9] => array         (             [0] => our company             [1] => 11             [2] => 11             [3] => 07/25/2017 5:12:06 pm             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => fingerpint             [9] =>          )      [10] => array         (             [0] => our company             [1] => 112             [2] => 112             [3] => 07/25/2017 8:43:56             [4] => check in             [5] => 1             [6] =>              [7] => 0             [8] => password             [9] =>          )      [11] => array         (             [0] => our company             [1] => 112             [2] => 112             [3] => 07/25/2017 5:39:26 pm             [4] => check out             [5] => 1             [6] =>              [7] => 0             [8] => password             [9] =>          )  ) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -