项目作者: jfcherng

项目描述 :
Dump an array into XML, JSON, YAML, etc...
高级语言: PHP
项目地址: git://github.com/jfcherng/php-array-dumper.git
创建时间: 2018-06-19T11:27:29Z
项目社区:https://github.com/jfcherng/php-array-dumper

开源协议:MIT License

下载


php-array-dumper

GitHub Workflow Status (branch)
Packagist
Packagist Version
Project license
GitHub stars
Donate to this project using Paypal

Dump an array into XML, JSON, YAML, etc…

Installation

  1. $ composer require jfcherng/php-array-dumper

Example

See demo.php.

  1. <?php
  2. include __DIR__ . '/vendor/autoload.php';
  3. use Jfcherng\ArrayDumper\DumperFactory;
  4. $array = [
  5. 0 => 'zero',
  6. '*' => 'bar',
  7. 'deep' => [
  8. 'list' => ['zero', 'one', '二'],
  9. 'map' => ['zero' => 0, 'one' => 1, '二' => 2],
  10. ],
  11. ];
  12. // 'json', 'xml', 'yaml', 'php'
  13. $dumperName = 'yaml';
  14. // initiate a dumper and optionally set its options
  15. $dumper = DumperFactory::make($dumperName, [
  16. 'indent' => 2,
  17. ]);
  18. // dump into a string
  19. $string = $dumper->dump($array);
  20. /*
  21. string(83) "0: zero
  22. '*': bar
  23. deep:
  24. list: [zero, one, 二]
  25. map: { zero: 0, one: 1, 二: 2 }
  26. "
  27. */
  28. var_dump($string);
  29. // dump as an external file
  30. $outputFile = __DIR__ . '/results/test.' . $dumper::EXTENSION;
  31. $success = $dumper->toFile($array, $outputFile);