循环给array_merge里加函数的问题

WBOY
Release: 2016-06-06 20:43:16
Original
1074 people have browsed it

有个数组
循环给array_merge里加函数的问题

我想让红框里的键值连续0123456789而不是每次都重新0123,0123
想道用array_merge重新整合,但是不知道循环该怎么写
麻烦各位给个思路或者新的好方法

回复内容:

有个数组
循环给array_merge里加函数的问题

我想让红框里的键值连续0123456789而不是每次都重新0123,0123
想道用array_merge重新整合,但是不知道循环该怎么写
麻烦各位给个思路或者新的好方法

<code>function merge($prev, $now) {
    return array_merge($prev, $now['item_data']);
}
array_reduce($arr, "merge", array());
</code>
Copy after login

http://3v4l.org/uL6cS

<code class="lang-php"><br>function arr_merge($arr) {
    static $str;
    if (!is_array($arr)) {
        return $arr;
    }
    foreach ($arr as $key => $val ) {

    if (is_array($val)) {

        arr_merge($val);
    } else {

      $str[] = $val;
    }
    }
    return $str;
}
</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template