当前位置:网站首页>PHP takes the difference set of two arrays
PHP takes the difference set of two arrays
2022-06-25 12:29:00 【Chafferer WANG】
Replace with the following method array_diff()
/** Application scenarios : for example : Two existing arrays $arr1, $arr2 $arr1 = ['a', 'a', 'b']; $arr2 = ['a', 'b', 'b']; If we want to take at this time arr1 But not in arr2 When data in , Use array_diff($arr1, $arr2) The output result is []; Use array_diff_repeat($arr1, $arr2) The output is ['temp_arr1' => 'a', 'temp_arr2' => 'b']; * The ginseng :$arr1,$arr2 */
public function array_diff_repeat($arr1, $arr2) {
$temp_arr1 = [];// stay $arr1 But not in $arr2 Data in
$temp_arr2 = [];// stay $arr2 But not in $arr1 Data in
foreach ($arr1 as $arr1_key => $arr1_id) {
$index_id = array_search($arr1_id, $arr2, true);
if($index_id !== false) {
unset($arr1[$arr1_key]);
unset($arr2[$index_id]);
} else {
array_push($temp_arr1, $arr1_id);
}
}
foreach ($arr2 as $arr2_key => $arr2_id) {
$index_id = array_search($arr2_id, $arr1, true);
if($index_id !== false) {
unset($arr1[$arr2_key]);
unset($arr2[$index_id]);
} else {
array_push($temp_arr2, $arr2_id);
}
}
return ['temp_arr1' => $temp_arr1, 'temp_arr2' => $temp_arr2];
}
边栏推荐
- 网络 | traceroute,路由跟踪命令,用于确定 IP 数据包访问目标地址所经过的路径。
- Kotlin基础
- Image tagging to obtain the coordinates of the image in the ImageView
- High imitation blue playing network disk file sharing to make money network disk PHP system source code
- Controllable character image synthesis based on attribute decomposition and Gan reproduction
- Learning notes 2022 overview | automatic graph machine learning, describing AGML methods, libraries and directions
- 学习笔记 2022 综述 | 自动图机器学习,阐述 AGML 方法、库与方向
- ARM 立即数
- Explanation of ideas and sharing of pre-processing procedures for 2021 US game D (with pre-processing data code)
- SQL function summary
猜你喜欢
Linear regression of common mathematical modeling models for College Students
揭秘GaussDB(for Redis):全面對比Codis
一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
Dark horse shopping mall ---2 Distributed file storage fastdfs
Flutter common commands and problems
Uncover gaussdb (for redis): comprehensive comparison of CODIS
Why can't you Ping the website but you can access it?
[论]Learning Dynamic and Hierarchical Traffic Spatiotemporal Features with Transformer
19. Implementation of MVVM architecture based on WPF event to command
PD1.4转HDMI2.0转接线拆解。
随机推荐
Qiantang Pingou source code -- Qiantang Pingou app system development source code sharing
ECSHOP product attribute color specification size stock item No. automatic combination
ECSHOP whole site custom URL supports directory type
A commonly used statistical modeling method -- difference analysis
Linear regression of common mathematical modeling models for College Students
ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
Hook技术
15、wpf之button样式小记
Hook technology
揭秘GaussDB(for Redis):全面對比Codis
Execution order of MySQL query statements join, on and where
The source code of the hottest online disk money making system in 2022 imitates Lanzou online disk / Chengtong online disk / sharing money making cloud disk system / online disk VIP Download System
New and old cluster migration of Minio data
The whole page turns gray
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the lrtest function of epidisplay package to perform multiple model
flutter常用命令及问题
Controllable character image synthesis based on attribute decomposition and Gan reproduction
Renrenyue -- renrenyue system development source code sharing
The first techo day Tencent technology open day in 2022 will be held online on June 28
The network traceroute command is used to determine the path through which IP packets access the destination address.