I wanted to add a value on my array if it exist.If not then create a new one.
$orders = array(
array("qty" => 3,"piece_type"=> "Documents (Up to 1kg)"),
array("qty" => 2,"piece_type"=> "Documents (Up to 1kg)"),
array("qty" => 4,"piece_type"=> "Large (10-20kg 150cm)")
);
$sizes = array(
"Documents (Up to 1kg)"=>10,
"Large (10-20kg 150cm)"=>20
);
$wpc_total_cost = array();
$i = 0;
foreach( $orders as $value )
{
$i++;
$wpc_total_cost[$value['piece_type']] += $value['qty'] * $sizes[$value['piece_type']];
}
print_r($wpc_total_cost);
I tried array_exist I don't quite get the logic.
my error :
NOTICE Undefined index: Documents (Up to 1kg) on line number 21
NOTICE Undefined index: Large (10-20kg 150cm) on line number 21
Array ( [Documents (Up to 1kg)] => 50 [Large (10-20kg 150cm)] => 80 )