Google

Saturday, May 23, 2009

How to read integer value from XML in PHP and after read add those value

When you read XML in php through simple xml class then at the time of integer value you need to type cast those value in "string", because
when you read through simple xml class object then he return the object(show through the var_dump).

Ex:

your XML look like -










now you want to read both ints tag value and add both value.


/*


$xml->load('abc.xml');

foreach($xml->a[0] as $abTagObj)
{

$ints[] = (String)$abTagObj->ints;
}

array_sum($ints); // show the total of all ints tag.

*/


but if you not type cast ints tag value as "string" then when you go for add then show the total as 0.


If still any question then pleases put your comment i will answer you. or any question regarding PHP, javascript, ajax, css, html, mysql put your comment feel free.