Pretty newbie question :/
I have an API that returns values, I just want to get the number of elements in XML but its limited to 30 per query.
function SOMEfunction($number){
$curl = curl_init("*URL*?format=xml&page=" . $number);
$result = curl_exec($curl);
$xml = simplexml_load_string($result);
$ttn = $xml->count();
echo "$ttn<br>";
}
so, Since I just want to get the number of elements in XML, i run a short while loop, which i want to sum somehow.
$sum=0;
$num=1;
while ($num < 7)
{
$sum += SOMEfunction($num);
$num++;
}
echo $sum;
the current out put is:
30
30
30
30
2
0
0
How can i sum them up?
Thanks.
echo "$ttn<br>";should bereturn $ttn;Try making that change and combine it with the answer I posted and see if that works.VALUEwill be possibly treated as a constant by PHP.$curlcoming from? What does it look like. Maybe you should pass$curlas an argument to your function in place ofVALUE. I am not sure if that will work even.$sumvariable. Ideally you should not even be getting the output that you are currently getting. It should just be a single value.