Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $array = [
- ['a', 'b'],
- ['c', ['d','e']],
- 'f',
- ['g']
- ];
- function flattening_array(array $items, array &$flattened = [])
- {
- foreach ($items as $item) {
- if( is_array($item) )
- {
- flattening_array($item, $flattened);
- continue;
- }
- $flattened[] = $item;
- }
- }
- $flat_array = [];
- flattening_array($array,$flat_array);
- print_r( $flat_array );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment