Parsing log file

I’m trying to group together all entries within my last few lines of my apache log file, but struggling!

 for($i=$count - 100; $i<$count; $i++){
	$line = $display[$i];	

	preg_match("/^(\\S+) (\\S+) (\\S+) \\[([^:]+):(\\d+:\\d+:\\d+) ([^\\]]+)\\] \\"(\\S+) (.*?) (\\S+)\\" (\\S+) (\\S+) (\\".*?\\") (\\".*?\\")$/", $line, $logs); // pattern to format the line

      $formated_log['ip'] = $logs[1];
     // $formated_log['identity'] = $logs[2];
     // $formated_log['user'] = $logs[2];
      $formated_log['date'] = $logs[4];
      $formated_log['time'] = $logs[5];
      //$formated_log['timezone'] = $logs[6];
     // $formated_log['method'] = $logs[7];
     // $formated_log['path'] = $logs[8];
      //$formated_log['protocal'] = $logs[9];
      $formated_log['status'] = $logs[10];
      //$formated_log['bytes'] = $logs[11];
     // $formated_log['referer'] = $logs[12];
     // $formated_log['agent'] = $logs[13];

	foreach ($formated_log as $a=>$b){

		$item .= "<td>$b</td>\
";

	}
	$groups[$formated_log['ip']]=array($item);


 }

How would i group the $item entries by IP?

Try this:

$groups = array();
for($i=$count - 100; $i<$count; $i++){
	$line = $display[$i];	

	$logs = array();
	if (!preg_match("/^(\\S+) (\\S+) (\\S+) \\[([^:]+):(\\d+:\\d+:\\d+) ([^\\]]+)\\] \\"(\\S+) (.*?) (\\S+)\\" (\\S+) (\\S+) (\\".*?\\") (\\".*?\\")$/", $line, $logs)) continue; // pattern to format the line

	$formated_log['ip'] = $logs[1];
	// $formated_log['identity'] = $logs[2];
	// $formated_log['user'] = $logs[2];
	$formated_log['date'] = $logs[4];
	$formated_log['time'] = $logs[5];
	// $formated_log['timezone'] = $logs[6];
	// $formated_log['method'] = $logs[7];
	// $formated_log['path'] = $logs[8];
	// $formated_log['protocal'] = $logs[9];
	$formated_log['status'] = $logs[10];
	// $formated_log['bytes'] = $logs[11];
	// $formated_log['referer'] = $logs[12];
	// $formated_log['agent'] = $logs[13];

	$item = '';
	foreach ($formated_log as $value){
		$item .= '<td>'.htmlentities($value, ENT_QUOTES, 'UTF-8')."</td>\
";
	}

	if (!isset($groups[$formated_log['ip']])) $groups[$formated_log['ip']] = array();
	$groups[$formated_log['ip']][] = $item;
 }

Then you should be able to access $groups[‘127.0.0.1’] (for example) to get an array of all log lines for that IP address.