* [refac,done,0.1h] To move the position of the arrayUnion function on the mobile.
This commit is contained in:
@@ -1473,3 +1473,31 @@ if(!interface_exists('JsonSerializable'))
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个或多个数组附加到第一个数组,用于替换数组 + 运算符。
|
||||
* Append one or more arrays to the first array, used to replace the array + operator.
|
||||
*
|
||||
* reference: https://www.php.net/manual/en/language.operators.array.php.
|
||||
*
|
||||
* @param array ...$args
|
||||
* @return array
|
||||
*/
|
||||
function arrayUnion(...$args): array
|
||||
{
|
||||
$args = array_filter($args, function($arg){return is_array($arg);});
|
||||
|
||||
$count = count($args);
|
||||
if($count == 0) return [];
|
||||
if($count == 1) return reset($args);
|
||||
|
||||
$result = array_shift($args);
|
||||
foreach($args as $arg)
|
||||
{
|
||||
foreach($arg as $key => $value)
|
||||
{
|
||||
if(!isset($result[$key])) $result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -869,31 +869,3 @@ function addPrefixToField(&$data, $fieldName, $suffix = '. ')
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把一个或多个数组附加到第一个数组,用于替换数组 + 运算符。
|
||||
* Append one or more arrays to the first array, used to replace the array + operator.
|
||||
*
|
||||
* reference: https://www.php.net/manual/en/language.operators.array.php.
|
||||
*
|
||||
* @param array ...$args
|
||||
* @return array
|
||||
*/
|
||||
function arrayUnion(...$args): array
|
||||
{
|
||||
$args = array_filter($args, function($arg){return is_array($arg);});
|
||||
|
||||
$count = count($args);
|
||||
if($count == 0) return [];
|
||||
if($count == 1) return reset($args);
|
||||
|
||||
$result = array_shift($args);
|
||||
foreach($args as $arg)
|
||||
{
|
||||
foreach($arg as $key => $value)
|
||||
{
|
||||
if(!isset($result[$key])) $result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user