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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
d474133c
Commit
d474133c
authored
May 15, 2013
by
Veaceslav Medvedev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make multisort compatible with Sort
Test code ```php $orders = $this->getSort()->getOrders(); ArrayHelper::multisort($data, array_keys($orders), array_values($orders)); ```
parent
6431019a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
ArrayHelper.php
yii/helpers/base/ArrayHelper.php
+5
-5
No files found.
yii/helpers/base/ArrayHelper.php
View file @
d474133c
...
...
@@ -275,16 +275,16 @@ class ArrayHelper
* @throws InvalidParamException if the $ascending or $sortFlag parameters do not have
* correct number of elements as that of $key.
*/
public
static
function
multisort
(
&
$array
,
$key
,
$
ascending
=
tru
e
,
$sortFlag
=
SORT_REGULAR
,
$caseSensitive
=
true
)
public
static
function
multisort
(
&
$array
,
$key
,
$
descending
=
fals
e
,
$sortFlag
=
SORT_REGULAR
,
$caseSensitive
=
true
)
{
$keys
=
is_array
(
$key
)
?
$key
:
array
(
$key
);
if
(
empty
(
$keys
)
||
empty
(
$array
))
{
return
;
}
$n
=
count
(
$keys
);
if
(
is_scalar
(
$
a
scending
))
{
$
ascending
=
array_fill
(
0
,
$n
,
$a
scending
);
}
elseif
(
count
(
$
a
scending
)
!==
$n
)
{
if
(
is_scalar
(
$
de
scending
))
{
$
descending
=
array_fill
(
0
,
$n
,
$de
scending
);
}
elseif
(
count
(
$
de
scending
)
!==
$n
)
{
throw
new
InvalidParamException
(
'The length of $ascending parameter must be the same as that of $keys.'
);
}
if
(
is_scalar
(
$sortFlag
))
{
...
...
@@ -315,7 +315,7 @@ class ArrayHelper
}
else
{
$args
[]
=
static
::
getColumn
(
$array
,
$key
);
}
$args
[]
=
$
ascending
[
$i
]
?
SORT_ASC
:
SORT_DE
SC
;
$args
[]
=
$
descending
[
$i
]
?
SORT_DESC
:
SORT_A
SC
;
$args
[]
=
$flag
;
}
$args
[]
=
&
$array
;
...
...
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