当前位置:网站首页>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];
}
边栏推荐
- Record a debugging when curl has no return value
- 一款好用的印章设计工具 --(可转为ofd文件)
- 2022年首期Techo Day腾讯技术开放日将于6月28日线上举办
- Spicy food advertising e-commerce system development function and spicy food advertising e-commerce app system development source code sharing
- An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
- Set the transparency of the picture to gradient from left to right
- SQL function summary
- Gradle knowledge points
- ARM V7 连续加载/存储
- Arm V7 continuous load / store
猜你喜欢

How to use SPSS to do grey correlation analysis? Quick grasp of hand-to-hand Teaching

Service charge and time setting code sharing involved in crmeb withdrawal process

Pd1.4 to hdmi2.0 adapter cable disassembly.

Flutter common commands and problems

20. MVVM command binding of WPF

Dark horse shopping mall ---1 Project introduction - environment construction

ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function

揭秘GaussDB(for Redis):全面對比Codis

Use PHP script to view the opened extensions

Rank sum ratio comprehensive evaluation method for common models in mathematical modeling
随机推荐
How to use ARIMA model for prediction?
Tidb common commands
Hook技术
The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The type parameter specifies the line type of
Repair the error that ECSHOP background orders prompt insufficient inventory when adding goods. Please reselect
Renrenyue -- renrenyue system development source code sharing
网络 | traceroute,路由跟踪命令,用于确定 IP 数据包访问目标地址所经过的路径。
Implementing Domain Driven Design - using the ABP framework - Summary of a series of articles
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、epiDisplay包的poisgof函数对拟合的泊松回归模型进行拟合优度检验(检验模型效果)
R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
Dark horse shopping mall ---2 Distributed file storage fastdfs
Online blind box system development function introduction and some source code sharing
New and old cluster migration of Minio data
Set the transparency of the picture to gradient from left to right
Use PHP script to view the opened extensions
Dark horse shopping mall ---6 Brand, specification statistics, condition filtering, paging sorting, highlighting
Install MySQL client
Introduction to jiuhongtianxia system development function -- jiuhongtianxia app development source code sharing
The network traceroute command is used to determine the path through which IP packets access the destination address.
What is Flink? What can Flink do?