0

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 ?

1 Answer 1

1
<?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++;
}
Sign up to request clarification or add additional context in comments.

3 Comments

i have updated my answer after your comment. Please check now. The problem was just the two square brackets. Try now and i would love to know what happened.
what all together? How do you want?
helpful, after 9 years :O +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.