Skip to content

Commit 28de3a6

Browse files
committed
fix: 增加 array_column 兼容函数
1 parent 65c3dca commit 28de3a6

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

helper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
if (!function_exists('array_column')) {
4+
/**
5+
* PHP 版本兼容函数
6+
* @param $input
7+
* @param $columnKey
8+
* @param $indexKey
9+
* @return array
10+
*/
11+
function array_column($input, $columnKey, $indexKey = null)
12+
{
13+
$result = array();
14+
foreach ($input as $row) {
15+
if (isset($row[$columnKey])) {
16+
if ($indexKey !== null && isset($row[$indexKey])) {
17+
$result[$row[$indexKey]] = $row[$columnKey];
18+
} else {
19+
$result[] = $row[$columnKey];
20+
}
21+
}
22+
}
23+
return $result;
24+
}
25+
}

include.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
1515
// +----------------------------------------------------------------------
1616

17+
include_once __DIR__ . '/helper.php';
18+
1719
spl_autoload_register(function ($classname) {
1820
$pathname = __DIR__ . DIRECTORY_SEPARATOR;
1921
$filename = str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';

0 commit comments

Comments
 (0)