<?php
$prod=array('A','B','A','B','B');
$qty=array(1,1,1,1,1);
$price=array(100,150,100,150,150);
$mrp=array(200,230,200,230,230);
$tax=array('5.00~VAT~INVOICE','5.50~CST~TAXINV','6.00~VAT@~INVOICE','5.50~CST~TAXINV','5.50~CST~TAXINV');
print_r($prod);
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
print_r($price);
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
print_r($mrp);
echo "<br/>";
$uniq_prod=array_unique($prod);
print_r($uniq_prod);
echo "<br/>";
echo "<br/>";
echo "<br/>";
foreach($uniq_prod as $key => $value){
	//echo "key->".$key." value-->".$value."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$keyarr=array_keys($prod, $value);
	//print_r($keyarr);
	//echo "<br/>";
	$sum_qty=0;
	$sum_price=0.00;
	$sum_mrp=0.00;
	$sum_taxper=0.00;
	$sum_taxname="";
	$sum_taxhead="";
	$denominator=0;
	for($i=0;$i<count($keyarr);$i++){
		$sum_qty+=$qty[$keyarr[$i]];
		$sum_price+=$price[$keyarr[$i]];
		$sum_mrp+=$mrp[$keyarr[$i]];
		//// tax
		$taxpick=explode("~",$tax[$keyarr[$i]]);
		$sum_taxper+=$taxpick[0];
		//if($sum_taxper){$sum_taxper.=",".$taxpick[0];}else{$sum_taxper.=$taxpick[0];}
		if($sum_taxname){$sum_taxname.=",".$taxpick[1];}else{$sum_taxname.=$taxpick[1];}
		if($sum_taxhead){$sum_taxhead.=",".$taxpick[2];}else{$sum_taxhead.=$taxpick[2];}
		$denominator++;
	}
	$unique_taxname = implode(',',array_unique(explode(',', $sum_taxname)));
	//echo $denominator;
	echo $value." qty->".$sum_qty." price->".$sum_price/$denominator." mrp->".$sum_mrp/$denominator." Taxper->".$sum_taxper/$denominator." TaxName->".$unique_taxname."<br/>";
}
?>