Convert an array to another data format or convert a data format to an array.
- JSON
- XML
- PHP internal session serialized data
- PHP internal binary serialized data
- PHP Serialized() data
- YAML
- WDDX support
- igbinary support
composer require geeklab/arraytranslation
<?php
require_once('../vendor/autoload.php');
$at = \GeekLab\ArrayTranslation::create('yaml');
$out = $at->encode(array('a' => 'x', 'b' => y', 'c' => 'z');
This is the factory to return the class for array<->data type translation.
$type
can be set to xml, json, yaml, php, php_binary or php_binary for now.
$handler
is for pointing to a customer handler. Must implement GeekLab\ArrayTranslation\TranslationInterface
$at = \GeekLab\ArrayTranslation::create('json');
This method will convert an array to the type the object was created with.
$x = $at->encode(array('a', 'b', 'c'));
This method will convert a string (data type) to an array.
$y = $at->decode('["a","b","c"]');