Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Rock Zhang
9 years ago
Commit
5fc863e9a0e8c6fda42d44504c2aead62bb0a3c3
1 parent
08d4ec6f
修复低版本php不兼容aray_column的问题
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
1 deletions
yohobuy/m.yohobuy.com/application/models/Category/Class.php
yohobuy/m.yohobuy.com/application/models/Category/Class.php
View file @
5fc863e
...
...
@@ -108,11 +108,51 @@ class ClassModel
foreach
(
$classesData
as
$val
)
{
foreach
(
$val
[
'ca'
]
as
$single
)
{
$classes
[
$single
[
'id'
]]
=
$single
[
'name'
];
$classes
+=
array_column
(
$single
[
'sub'
],
'name'
,
'id'
);
$classes
+=
self
::
array_column
(
$single
[
'sub'
],
'name'
,
'id'
);
}
}
return
$classes
;
}
/**
* 自定义array_column函数
*
* @return array 返回数组中指定的一列组成的数组
*/
/**
* 自定义array_column函数
* @param array $input 需要取出数组咧的多维数组
* @param string $columnKey 需要返回的列
* @param mixed $indexKey 作为返回数组的索引值
* @return array 从多维数组中返回单列数组
*/
private
static
function
array_column
(
array
$input
,
$columnKey
,
$indexKey
=
null
)
{
$array
=
array
();
foreach
(
$input
as
$value
)
{
if
(
!
isset
(
$value
[
$columnKey
]))
{
trigger_error
(
"Key
\"
$columnKey
\"
does not exist in array"
);
return
false
;
}
if
(
is_null
(
$indexKey
))
{
$array
[]
=
$value
[
$columnKey
];
}
else
{
if
(
!
isset
(
$value
[
$indexKey
]))
{
trigger_error
(
"Key
\"
$indexKey
\"
does not exist in array"
);
return
false
;
}
if
(
!
is_scalar
(
$value
[
$indexKey
]))
{
trigger_error
(
"Key
\"
$indexKey
\"
does not contain scalar value"
);
return
false
;
}
$array
[
$value
[
$indexKey
]]
=
$value
[
$columnKey
];
}
}
return
$array
;
}
}
...
...
Please
register
or
login
to post a comment