Advertisement
Danack

Flatten

Aug 24th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1.  
  2. function flatten($inputArray) {
  3. $output = '';
  4. foreach ($inputArray as $element) {
  5. if (is_array($element) == true) {
  6. $output .= flatten($element);
  7. }
  8. else {
  9. $output .= $element;
  10. }
  11. }
  12.  
  13. return $output;
  14. }
  15.  
  16.  
  17. $print = array(
  18. 'orange',
  19. 'green',
  20. array(
  21. 'yellow',
  22. 'white'
  23. )
  24. );
  25.  
  26. echo flatten($print);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement