3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multiple = [ 'Mobiles' => [ 'MobileNo' => ['123', '456'] ] ]; $single = [ 'Mobiles' => [ 'MobileNo' => '123' ] ]; 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['Mobiles'] as $pNumber) { foreach($pNumber as $mobile ){ $i++; $array[$i]['SubmitResult'] = [ 'MobileNo' => $mobile, '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:
17.76 ms | 402 KiB | 8 Q