Skip to content

Commit

Permalink
fix: 增加 array_column 兼容函数
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujingli committed Aug 4, 2024
1 parent 65c3dca commit 28de3a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

if (!function_exists('array_column')) {
/**
* PHP 版本兼容函数
* @param $input
* @param $columnKey
* @param $indexKey
* @return array
*/
function array_column($input, $columnKey, $indexKey = null)
{
$result = array();
foreach ($input as $row) {
if (isset($row[$columnKey])) {
if ($indexKey !== null && isset($row[$indexKey])) {
$result[$row[$indexKey]] = $row[$columnKey];
} else {
$result[] = $row[$columnKey];
}
}
}
return $result;
}
}
2 changes: 2 additions & 0 deletions include.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------

include_once __DIR__ . '/helper.php';

spl_autoload_register(function ($classname) {
$pathname = __DIR__ . DIRECTORY_SEPARATOR;
$filename = str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
Expand Down

0 comments on commit 28de3a6

Please sign in to comment.