Skip to content

Latest commit

 

History

History
34 lines (30 loc) · 710 Bytes

File metadata and controls

34 lines (30 loc) · 710 Bytes

php-json-to-array-to-code

Convert JSON object to PHP array or render array as PHP code

把一个PHP数组变量转换成PHP代码,可方便地用于生成配置文件.

Usage

include(__DIR__ . '/src.php');
$json = '{  
   "hello":"world",
   "properties":{  
      "url":"https://github.com/matejbukovsky/php-json-to-array",
      "convert":true
   },
   "test": ["first", "second", 0]
}';

Return PHP code

$code = '$array = ';
$code .= getCode(json_decode($json, TRUE));
$code .= ';';

echo $code;

$array = [
	'hello' => 'world',
	'properties' => [
		'url' => 'https://github.com/matejbukovsky/php-json-to-array',
		'convert' => TRUE
	],
	'test' => ['first','second',0]
];