How to get sum value of sub-child element in xml file

I need to get the sum total of a sub-child element from mxl file My structure of xml file is as follow

<pagevalues>
    <ac>
        <b1>1</b1>
        <b2>2</b2>
        <b3>3</b3>
        <b4>4</b4>
        <b5>5</b5>
        <pc>6</pc>
    </ac>
<pagevalues> 

I tried following approach but get Total =0

$xml = simplexml_load_file($target_url);
$total=0;
foreach($xml->ac as $data)
{    
    $total += $data;
}
echo 'Total is: ' . $total;
1 Like

Got answer from https://stackoverflow.com/users/1213708/nigel-ren

Perhaps you could give the link to the answer rather than to the guy who answered it @johan?

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.