I have a csv file and it has four fields which are time,sip,dip and data.
I need to find all sips which starts with "10." and if sips are same add all data field and display the value with sip.
I have tried the code below. But how can I search the array to check whether sips are same, if they are same add all data field.
$lines =file('/files/cjsv.csv');
$records=array();
foreach($lines as $data)
{
list($time,$sip,$dip,$data)= explode(',',$data);
if(substr($sip, 0, 3 )=="10.")
{
echo $sip."=".$data."<br/>";
$records[$sip]=$data;
}
}
var_dump($records);
Example of a csv file:
2014-10-31 23:34:24,17.172.208.49,10.101.224.170,500
2014-10-31 23:34:16,178.206.115.117,10.101.224.170,400
2014-10-31 23:34:23,10.101.16.218,17.167.138.38,200
2014-10-31 23:34:23,10.101.16.218,17.167.138.38,100
2014-10-31 23:34:24,54.249.250.113,10.101.13.22,80
2014-10-31 23:34:24,17.167.140.109,10.101.1.1,80
2014-10-31 23:34:24,134.170.188.84,10.101.1.1,80
2014-10-31 23:34:23,10.101.16.219,17.167.138.38,50
Expected output is:
10.101.16.218=300(200+100)
10.101.16.219=50