3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_1 = '[{"MobileNo":"123"},{"MobileNo":"456"}]'; $json_2 = '[{"MobileNo":"07123456701"}]'; $multiple = json_decode($json_1, true); $single = json_decode($json_2, true); class convert{ public function arrayToXml($array, $xml) { foreach ($array as $key => $value) { if (is_array($value)) { self::arrayToXml($value, $xml->addChild($key)); } else { if (is_numeric($key)) { $xml->addChild(preg_replace('/s$/', '', $xml->getName()), $value); } else { $xml->addChild($key, $value); } } } } } $xml = new \SimpleXMLElement('<Msg />'); $array = [ 'JobId' => 77]; $i = 0; foreach ($multiple as $mobile) { $i++; $array[$i]['SubmitResult'] = [ 'MobileNo' => $mobile['MobileNo'], 'StatusId' => 0000, 'StatusText' =>'Success: Message submitted successfully', ]; } //print_r($array); $convert = new convert(); $convert->arrayToXml($array, $xml); var_dump($xml->asXML());
Output for git.master_jit, git.master, rfc.property-hooks
string(343) "<?xml version="1.0"?> <Msg><JobId>77</JobId><1><SubmitResult><MobileNo>123</MobileNo><StatusId>0</StatusId><StatusText>Success: Message submitted successfully</StatusText></SubmitResult></1><2><SubmitResult><MobileNo>456</MobileNo><StatusId>0</StatusId><StatusText>Success: Message submitted successfully</StatusText></SubmitResult></2></Msg> "

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
76.34 ms | 402 KiB | 8 Q