Fix compatibility with PHP 5.4

This commit is contained in:
zhangrunyu
2022-01-13 10:14:15 +08:00
parent 8ab6050b34
commit 39e30fc64f
10 changed files with 77 additions and 35 deletions
+36
View File
@@ -902,3 +902,39 @@ function htmlSpecialString($string, $flags = '', $encoding = 'UTF-8')
if(!$flags) $flags = defined('ENT_SUBSTITUTE') ? ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 : ENT_QUOTES;
return htmlspecialchars($string, $flags, $encoding);
}
if (!function_exists('array_column'))
{
function array_column(array $input, $columnKey, $indexKey = null)
{
$output = array();
foreach ($input as $row) {
$key = $value = null;
$keySet = $valueSet = false;
if (null !== $indexKey && array_key_exists($indexKey, $row)) {
$keySet = true;
$key = (string) $row[$indexKey];
}
if (null === $columnKey) {
$valueSet = true;
$value = $row;
} elseif (\is_array($row) && \array_key_exists($columnKey, $row)) {
$valueSet = true;
$value = $row[$columnKey];
}
if ($valueSet) {
if ($keySet) {
$output[$key] = $value;
} else {
$output[] = $value;
}
}
}
return $output;
}
}