Reputation:
i am getting data from xml feed and then using foreach loop inserting data in mysql.
but xml feed contains multiple items with same attribute like this
but what i want is ,
the addition of subitems of the attributes having same values
as xml shows the attribute tag1111 has 3 types of values
if i add something in foreach loop it gets replaced for every loop.
how can i do this ?
Upvotes: 0
Views: 471
Reputation: 2291
<?php
$requestUrl = "url";
$data = simplexml_load_file($requestUrl);
$i=0;
foreach($data->item as $subitem) {
if(!in_array($data->item[$i]['promocode'], $arr_promocode))
$arr_promocode[] = $data->item[$i]['promocode'];
else{
$key = array_search($data->item[$i]['promocode'], $arr_promocode);
$data->item[$key]['clicks'] = $data->item[$key]['clicks'] + $subitem->clicks;
}
$arr_program[] = $data->item[$i]['program'];
$arr_program_name[] = $data->item[$i]['program_name'];
$clicks = $subitem->clicks;
$total = $subitem->total;
$i++;
}
Upvotes: 1