PHP code example of noresources / ns-php-data

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

    

noresources / ns-php-data example snippets


use NoreSources\Data\Serialization\SerializationManager;

$serializer = SerializationManager::getInstance();
$data = $serializer->unserializeFromFile ('foo.json');
$serializer->serializeToFile ('bar.yaml', $data);


use NoreSources\Data\Serialization\SerializationManager;
use NoreSources\MediaType\MediaTypeFactory;

$data = [
	'foo' => 'bar',
	'int' => 42,
	'list' => [
		1,
		2,
		3
	],
	'object' => [
		'firstName' => 'John',
		'lastName' => 'Doe'
	],
	'bool' => true,
	'null' => null
];

$luaMediaType = MediaTypeFactory::getInstance()->createFromString(
	'text/x-lua; mode=module');

$serializer = new SerializationManager();
$lua = $serializer->serializeData($data, $luaMediaType);
die($lua . PHP_EOL);