Created
September 25, 2019 12:36
-
-
Save Kcko/edde8bef39e71436f4533bfc02a4780c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = [ | |
'company' => 'AMI', | |
'employeeCount' => 25, | |
'years' => 12, | |
'bankInfo' => [ | |
'account' => 'xxxx', | |
'money' => '2 billions' | |
] | |
]; | |
echo F::create()->getResource($arr)->formatToXml(); | |
class F | |
{ | |
private $resource; | |
public static function create() | |
{ | |
return new self; | |
} | |
public function getResource($resource) | |
{ | |
$this->resource = $resource; | |
return $this; | |
} | |
public function formatToJson() | |
{ | |
return json_encode($this->resource); | |
} | |
public function formatToArray() | |
{ | |
return $this->resource; | |
} | |
public function formatToXml() | |
{ | |
$xml = new SimpleXMLElement('<root/>'); | |
array_walk_recursive($this->resource, array ($xml, 'addChild')); | |
return $xml->asXML(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment