PHP code example of ttree / serializer
1. Go to this page and download the library: Download ttree/serializer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ttree / serializer example snippets
class ObjectUtility {
/**
* @Flow\Inject
* @var \Ttree\Serializer\SerializerInterface
*/
protected $serializer;
/**
* @param object $object
* @return string
*/
public function save($object) {
$json = $this->serializer->serialize($object);
}
/**
* @param string $string
* @return object
*/
public function load($string) {
$json = $this->serializer->unserialize($string);
}
}
$serialize = new Serialize();
$json = $serialize(array('Hello', 'World'));
$unserialize = new Unserialize();
$array = $unserialize('["Hello","World"]')