Parse XML the search the array



I have to parse an XML file and foreach value of family type I need to add few values corresponding to those types in the array. for example -- for this part of XMl --



<family type="8400">
<value>8200</value>
<value>8200FIPS</value>
</family>


and this part of array --



[70] => 8200 [71] => 1083 [72] => 8200FIPS [73] => 4


I want to add values at index 71 and 73, i.e, 1083 + 4 and keep it in a new array as [0] => 8200 1 => 1084.


How this can be done. Pls guide, I am very new to XML and php.


output of --



$xml = simplexml_load_file('family_type.xml');
print_r( $xml);


is



SimpleXMLElement Object
( [family] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 2920 ) [value] => 2920 )
[1] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 2620 ) [value] => 2620 )
[2] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 2915 ) [value] => 2915 )
[3] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 3500 ) [value] => Array ( [0] => 3500jr [1] => 3500strk [2] => 3500 ) )
[4] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 3800 ) [value] => 3800 )
[5] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 5400 ) [value] => Array ( [0] => 5400 [1] => 5400FIPS ) )
[6] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 5400R ) [value] => Array ( [0] => 5400R [1] => 5400RFIPS ) )
[7] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 6600 ) [value] => 6600 )
[8] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 8200 ) [value] => 8200 )
[9] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => 8400 ) [value] => Array ( [0] => 8400 [1] => 8400FIPS ) )
[10] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => stack-AR ) [value] => stack-AR )
[11] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => stack-TA ) [value] => stack-TA ) ) )


and the required array http://ift.tt/1onj7zQ


No comments:

Post a Comment