Skip to content

hkargc/php-array-to-code

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

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]
];

About

Convert JSON object to PHP array

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%