Advertisement
Guest User

Untitled

a guest
May 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /*
  2. * 返回多维数组里的一维数组元素
  3. * @author MAGENJIE(magenjie@variflight.com)
  4. * @datetime 2019-04-18T14:38:31+0800
  5. * $a = [ 'a' => ['b' => ['c','e','f']], 'd' => ['11','22','33'], 'g' => 'xxx'];
  6. * $b = array_element_recursive($a);
  7. * var_dump($b);
  8. * array(3) {
  9. [0]=>
  10. array(3) {
  11. [0]=>
  12. string(1) "c"
  13. [1]=>
  14. string(1) "e"
  15. [2]=>
  16. string(1) "f"
  17. }
  18. [1]=>
  19. array(3) {
  20. [0]=>
  21. string(2) "11"
  22. [1]=>
  23. string(2) "22"
  24. [2]=>
  25. string(2) "33"
  26. }
  27. [2]=>
  28. string(3) "xxx"
  29. * }*/
  30. if (!function_exists('array_element_recursive')) {
  31. function array_element_recursive($array, &$return = []){
  32. foreach ($array as $key => $value) {
  33. if (is_array($value)) {
  34. if (count($value) === count($value, 1)) {
  35. $return[] = $value;
  36. }else{
  37. array_element_recursive($value, $return);
  38. }
  39. }else{
  40. $return[] = $value;
  41. }
  42. }
  43. return $return;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement