Commit b6a8c609 authored by 王源's avatar 王源 🎧

添加获取两个数组中key相同,value不同的数据

parent 8886172e
...@@ -732,6 +732,37 @@ if (!function_exists('check_diff_val')) { ...@@ -732,6 +732,37 @@ if (!function_exists('check_diff_val')) {
} }
} }
if (!function_exists('get_diff_val')) {
/**
* 获取两个数组中key相同,value不同的数据
* 返回后者的数据
* @param array $list1
* @param array $list2
* @param array $excludeKey 排除的key数组
* @return array
* @author Zero
*/
function get_diff_val(array $list1, array $list2, array $excludeKey = [])
{
$diff = [];
foreach ($list1 as $key => $val) {
if (!in_array($key, $excludeKey)) {
if (isset($list2[$key]) && $list2[$key] != '') {
if (is_array($val)) {
$temp = get_diff_val($val, $list2[$key], $excludeKey);
!empty($temp) && $diff[$key] = $temp;
} else {
if ($list1[$key] != $list2[$key]) {
$diff[$key] = $list2[$key];
}
}
}
}
}
return $diff;
}
}
if (!function_exists('to_camel_case')) { if (!function_exists('to_camel_case')) {
/** /**
* 下划线命名转驼峰命名 * 下划线命名转驼峰命名
...@@ -810,7 +841,7 @@ if (!function_exists('get_images_url')) { ...@@ -810,7 +841,7 @@ if (!function_exists('get_images_url')) {
*/ */
function get_images_url($str) function get_images_url($str)
{ {
preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$str,$match); preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i', $str, $match);
return $match; return $match;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment