alaasarhan / php-flatten Goto Github PK
View Code? Open in Web Editor NEWLicense: GNU Lesser General Public License v3.0
License: GNU Lesser General Public License v3.0
Flatten::flatten is a static function, but should be made non static and instances of flatten should be instantiated first with configuration variables (current arguments).
Hi,
We are happy to see the master branch changing config of composer for compatible with PHP8.
Is going to release the new version with this changed recently?
We are very appreciate and need your help.
thanks.
In the following snippet:
use Sarhan\Flatten;
$var = [
'a' => 'A',
'b' => 'B',
'c' => [ 'd' => 'D' ]
];
$flattened = Flatten::flatten($var, '.', '', Flatten::FLAG_NUMERIC_NOT_FLATTENED);
$flattened
IS:
print_r($flattened);
/*
Array
(
[] => Array
(
)
[a] => A
[b] => B
[c] => Array
(
)
[c.d] => D
)
*/
while it SHOULD BE:
print_r($flattened);
/*
Array
(
[a] => A
[b] => B
[c.d] => D
)
*/
Currently PSR-4 namespace configuration for this library is setup at the very root Sarhan\
. That's less optimal for other libraries under same root.
This need to be reconfigured to start with Sarhan\Flatten
pointing to the right source instead.
License library under LGPL
This function, when called on a flattened result, should produce an output equal to the original input that has been flattened using Flatten::flatten
function.
NUMERIC_NOT_FLATTENED
that switches off flattening numeric keys, and instead keep them in an array variable as described below:IS (without flag)
$flattened = Flatten::flatten([
'numericOnly' => ['A', 'B', 'C', 'D'],
'mixed' => [
'hello world!',
'js' => 'console.log("%s")',
'php' => 'echo "%s"'
]
]);
/* print_r($flattened)
Array
(
[numericOnly.0] => A
[numericOnly.1] => B
[numericOnly.2] => C
[numericOnly.3] => D
[mixed.0] => hello world!
[mixed.js] => console.log("%s")
[mixed.php] => echo "%s"
)
*/
SHOULD (with flag)
$flattened = Flatten::flatten([
'numericOnly' => ['A', 'B', 'C', 'D'],
'mixed' => [
'hello world!',
'js' => 'console.log("%s")',
'php' => 'echo "%s"'
]
], Flatten::NUMERIC_NOT_FLATTENED);
/* print_r($flattened)
Array
(
[numericOnly] => Array
(
[0] => A
[1] => B
[2] => C
[3] => D
)
[mixed] => Array
(
[0] => hello world!
)
[mixed.js] => console.log("%s")
[mixed.php] => echo "%s"
)
*/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.