Converting XML to Array in PHP code snippet

If you are trying to convert XML to an Array, then this is a snippet I have found useful in the past.

<?php
// Convert XML to Array
function xmlToArray($response){
	$xml = simplexml_load_string($response);
	$json = json_encode($xml);
	$arr = json_decode($json,true);
	return $arr;
}

Hope this helps you. If you are having any issues please leave a comment below.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *