PHP code example of oire / serializer

1. Go to this page and download the library: Download oire/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/ */

    

oire / serializer example snippets




use \Oire\Serializer;
$data = ["fruit" => "orange", "vegetable" => "carrot", "money" => 3000, "randomArray" => [1, 2, 3, 4, 5], "Lambë" => "Українська"];
try {
	// You can pass "j", "json" or 1 to setMode() to get JSON
	$jsonSerialized = (new Serializer())->setMode("json")->serialize($data);
} catch(Exception $e) {
	// Handle errors
}

// Without chaining it will be like this
$s = new Serializer();
// You may wrap this also with try...catch
$s->setMode("j");
try {
	$unserialized = $s->unserialize($jsonSerialized);
} catch(Exception $e) {
	// Handle errors
}

$msgPackSerialized = (new Serializer())->setMode("mp")->serialize($data, true);