PHP code example of bentools / flatten-iterator

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

    

bentools / flatten-iterator example snippets


use BenTools\FlattenIterator\FlattenIterator;

',
        'paris' => 'Paris',
    ],
    new \ArrayIterator([
        'berlin' => 'Berlin',
        'bruxelles' => 'Bruxelles',
    ]),
    (function () {
        yield 'budapest' => 'Budapest';
        yield 'prague' => 'Prague';
    })(),
];

foreach (new FlattenIterator($cities) as $city) {
    var_dump($city);
}

use function BenTools\FlattenIterator\flatten;
print_r(flatten($cities)->asArray());

array(6) {
  [0]=>
  string(6) "London"
  [1]=>
  string(5) "Paris"
  [2]=>
  string(6) "Berlin"
  [3]=>
  string(9) "Bruxelles"
  [4]=>
  string(8) "Budapest"
  [5]=>
  string(6) "Prague"
}

var_dump(flatten($cities, $preserveKeys = true)->asArray());