Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
1b6c24fe
Commit
1b6c24fe
authored
Apr 10, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
32757889
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
ArrayHelper.php
framework/util/ArrayHelper.php
+14
-9
No files found.
framework/util/ArrayHelper.php
View file @
1b6c24fe
...
@@ -19,7 +19,7 @@ namespace yii\util;
...
@@ -19,7 +19,7 @@ namespace yii\util;
class
ArrayHelper
extends
\yii\base\Component
class
ArrayHelper
extends
\yii\base\Component
{
{
/**
/**
* Merges two arrays into one recursively.
* Merges two
or more
arrays into one recursively.
* If each array has an element with the same string key value, the latter
* If each array has an element with the same string key value, the latter
* will overwrite the former (different from array_merge_recursive).
* will overwrite the former (different from array_merge_recursive).
* Recursive merging will be conducted if both arrays have an element of array
* Recursive merging will be conducted if both arrays have an element of array
...
@@ -27,22 +27,27 @@ class ArrayHelper extends \yii\base\Component
...
@@ -27,22 +27,27 @@ class ArrayHelper extends \yii\base\Component
* For integer-keyed elements, the elements from the latter array will
* For integer-keyed elements, the elements from the latter array will
* be appended to the former array.
* be appended to the former array.
* @param array $a array to be merged to
* @param array $a array to be merged to
* @param array $b array to be merged from
* @param array $b array to be merged from. You can specify additional
* arrays via third argument, fourth argument etc.
* @return array the merged array (the original arrays are not changed.)
* @return array the merged array (the original arrays are not changed.)
* @see mergeWith
*/
*/
public
static
function
merge
(
$a
,
$b
)
public
static
function
merge
(
$a
,
$b
)
{
{
foreach
(
$b
as
$k
=>
$v
)
{
$args
=
func_get_args
();
$res
=
array_shift
(
$args
);
while
(
$args
!==
array
())
{
$next
=
array_shift
(
$args
);
foreach
(
$next
as
$k
=>
$v
)
{
if
(
is_integer
(
$k
))
{
if
(
is_integer
(
$k
))
{
isset
(
$a
[
$k
])
?
$a
[]
=
$v
:
$a
[
$k
]
=
$v
;
isset
(
$res
[
$k
])
?
$res
[]
=
$v
:
$res
[
$k
]
=
$v
;
}
elseif
(
is_array
(
$v
)
&&
isset
(
$a
[
$k
])
&&
is_array
(
$a
[
$k
]))
{
}
elseif
(
is_array
(
$v
)
&&
isset
(
$res
[
$k
])
&&
is_array
(
$res
[
$k
]))
{
$a
[
$k
]
=
static
::
merge
(
$a
[
$k
],
$v
);
$res
[
$k
]
=
self
::
merge
(
$res
[
$k
],
$v
);
}
else
{
}
else
{
$a
[
$k
]
=
$v
;
$res
[
$k
]
=
$v
;
}
}
}
}
return
$a
;
}
return
$res
;
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment