Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 返回多维数组里的一维数组元素
- * @author MAGENJIE(magenjie@variflight.com)
- * @datetime 2019-04-18T14:38:31+0800
- * $a = [ 'a' => ['b' => ['c','e','f']], 'd' => ['11','22','33'], 'g' => 'xxx'];
- * $b = array_element_recursive($a);
- * var_dump($b);
- * array(3) {
- [0]=>
- array(3) {
- [0]=>
- string(1) "c"
- [1]=>
- string(1) "e"
- [2]=>
- string(1) "f"
- }
- [1]=>
- array(3) {
- [0]=>
- string(2) "11"
- [1]=>
- string(2) "22"
- [2]=>
- string(2) "33"
- }
- [2]=>
- string(3) "xxx"
- * }*/
- if (!function_exists('array_element_recursive')) {
- function array_element_recursive($array, &$return = []){
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- if (count($value) === count($value, 1)) {
- $return[] = $value;
- }else{
- array_element_recursive($value, $return);
- }
- }else{
- $return[] = $value;
- }
- }
- return $return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement