本文整理匯總了PHP中Illuminate\Support\Arr::merge_distinct方法的典型用法代碼示例。如果您正苦於以下問題:PHP Arr::merge_distinct方法的具體用法?PHP Arr::merge_distinct怎麽用?PHP Arr::merge_distinct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::merge_distinct方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: function
* @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk>
* @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com>
*/
Arr::macro('merge_distinct', function (array $array1, array $array2) {
$merged = $array1;
foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = Arr::merge_distinct($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
return $merged;
});
/**
* Combination of array_merge and array_merge_recursive, does merge news keys into an existing array, but
* overrides values instead of creating arrays from duplicate values.
*
* this is the splat version of Arr::merge_distinct which can only handle two input arrays.
*
* @return array
*/
Arr::macro('merge', function () {
$result = [];
$args = func_get_args();
$args_limit = func_num_args();
for ($i = 0; $i < $args_limit; $i++) {
$result = Arr::merge_distinct($result, $args[$i]);
}
return $result;
});