XML To array in php
612
i have to got response in XML . and i want to convert xml data to array using php. my XML record.
<soap:Body>
<CreateContact xmlns="http://www.tigerpawsoftware.com">
<pram>
<OfficePhoneNumber>8387909727</OfficePhoneNumber>
<EmailAddress>[email protected]</EmailAddress>
</pram>
</CreateContact>
</soap:Body>
Target Array as:-
array('OfficePhoneNumber' => 8387909727,
'EmailAddress' => [email protected] )
Answer
Solution:
Online Example: https://3v4l.org/KcJMX, You can optimize your primary array, Just learn from function.xml-parse-into-struct.php, I hope you will do it.
Use
xml_parser_create
andxml_parse_into_struct
to make your desire array.Using
xml_parse_into_struct
you will got two array, one is indexes and other is values. So you can generate your desire result from those index and values, As you the indexes you call easily make the desire array.Also look at those
($index, $vals)
arrays.Result
Answer
Solution:
You can achieve this using the simplexml_load_string() function
PHP
var_dump should output :
Here is a EvalIN