| 12345678910111213141516171819202122232425262728 |
- <?php
- namespace app\utils;
- class ArrayHelper
- {
- public static function merge($a, $b)
- {
- $args = func_get_args();
- $res = array_shift($args);
- while (!empty($args)) {
- foreach ((array)array_shift($args) as $k => $v) {
- if (is_int($k)) {
- if (array_key_exists($k, $res)) {
- $res[] = $v;
- } else {
- $res[$k] = $v;
- }
- } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) {
- $res[$k] = static::merge($res[$k], $v);
- } else {
- $res[$k] = $v;
- }
- }
- }
- return $res;
- }
- }
|