1. Go to this page and download the library: Download sarhan/php-flatten 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/ */
sarhan / php-flatten example snippets
use Sarhan\Flatten\Flatten;
$multiArray = [
'say' => 'what',
'hi' => [ 'de' => 'Hallo', 'es' => 'Hola' ]
];
/*
Flatten::__construct(
string $separator = '.',
string $prefix = '',
int $flags = 0
)
*/
$flatten = new Flatten();
// Flatten::flattenToArray is provided for convinience. It internally
// calls Flatten::flatten and converts it's output, which is a 1-dimensional
// iterator, into a 1-dimensional array.
$flattened = $flatten->flattenToArray($multiArray);
// Flatten::unflattenToArray is provided for convinience. It internally
// calls Flatten::unflatten and converts it's output, which is a recursive
// generator structure, into a multi-dimensional array.
$unflattened = $flatten->unflattenToArray($flattened);
assert($flattened == [
'say' => what
'hi.de' => Hallo
'hi.es' => Hola
]);
assert($unflattened == $multiArray);