GithubHelp home page GithubHelp logo

php-flatten's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-flatten's Issues

Make methods non static

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).

release new version for php8?

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.

Empty array is added when there's no numeric (keys) and FLAG_NUMERIC_NOT_FATTENED is used

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
)
*/

Fix namespace

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.

Allow not flattening numeric-keys

  • Add flags argument to flatten function to allow easy extendable.
  • Add a constant flag, 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"
)
*/
  • Cover with tests
  • Update documentation and README.md accordingly.
  • Adjust minor version, and create a release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.