There's the sum
-function in xpath
:
<list>
<a>1</a>
<a>3</a>
<a>4</a>
</list>
Now with SimpleXml
...
var_dump($xml->xpath("sum(/list/a)"));
delivers NULL
instead of 8
What's wrong here?
see it not working: https://eval.in/135558
EDIT: I've used this workaround for SimpleXml
to avoid iterating:
$sum = $xml->xpath("/list/a");
$sum = array_sum(array_walk("intval", $sum));