jfcherng / php-array-dumper
Dump an array into XML, JSON, YAML, etc...
Fund package maintenance!
www.paypal.me/jfcherng/5usd
Installs: 8 576
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.0.2
- nicmart/string-template: ~0.1.3
- spatie/array-to-xml: ^3
- symfony/yaml: ^5 || ^6 || ^7
Requires (Dev)
README
Dump an array into XML, JSON, YAML, etc...
Installation
$ composer require jfcherng/php-array-dumper
Example
See demo.php
.
<?php include __DIR__ . '/vendor/autoload.php'; use Jfcherng\ArrayDumper\DumperFactory; $array = [ 0 => 'zero', '*' => 'bar', 'deep' => [ 'list' => ['zero', 'one', '二'], 'map' => ['zero' => 0, 'one' => 1, '二' => 2], ], ]; // 'json', 'xml', 'yaml', 'php' $dumperName = 'yaml'; // initiate a dumper and optionally set its options $dumper = DumperFactory::make($dumperName, [ 'indent' => 2, ]); // dump into a string $string = $dumper->dump($array); /* string(83) "0: zero '*': bar deep: list: [zero, one, 二] map: { zero: 0, one: 1, 二: 2 } " */ var_dump($string); // dump as an external file $outputFile = __DIR__ . '/results/test.' . $dumper::EXTENSION; $success = $dumper->toFile($array, $outputFile);