当前位置:网站首页>For heavy two-dimensional arrays in PHP
For heavy two-dimensional arrays in PHP
2022-08-03 09:04:00 【Hello September!】
方法1:
$goods_terminal_unique = [];
$goods_terminal = [['goods_code'=>1,'terminal_code'=>12],['goods_code'=>1,'terminal_code'=>23],['goods_code'=>1,'terminal_code'=>12]];
for ($i = 0; $i < count($goods_terminal); $i++) {
$a = $goods_terminal[$i];
unset($goods_terminal[$i]);
if (!in_array($a, $goods_terminal_unique)) {
$goods_terminal_unique[] = $a;
}
}
var_dump($goods_terminal_unique);
方法2:降维(缺点:The original will be keys0,1,2,3…)
$temp = [];
$goods_terminal = [['goods_code'=>1,'terminal_code'=>12],['goods_code'=>1,'terminal_code'=>23],
foreach ($goods_terminal as $v) {
$v = join(",", $v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
$temp[] = $v;
}
var_dump($temp);
$temp = array_unique($temp);//去掉重复的字符串,也就是重复的一维数组
foreach ($temp as $k => $v) {
$temp[$k] = explode(",", $v);//再将拆开的数组重新组装
}
var_dump($temp);
边栏推荐
猜你喜欢
随机推荐
HCIA实验(07)
Industry SaaS Microservice Stability Guarantee Actual Combat
LINGO 18.0 software installation package download and installation tutorial
The display of the article list and the basics of creating articles and article details
响应式布局经典范例——巨幅背景大标题
关于Unity自定义Inspector面板的一些自定义编辑器扩展
10 minutes to get you started chrome (Google) browser plug-in development
dflow入门5——Big step & Big parameter
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之二:编码实现
dflow部署简记
HCIP练习02(OSPF)
Machine learning (formula derivation and code implementation)--sklearn machine learning library
SQL每日一练(牛客新题库)——第5天:高级查询
命令行加载特效 【cli-spinner.js】 实用教程
【微信小程序】底部有安全距离,适配iphone X等机型的解决方案
分区分表(一)
数仓4.0(二)------ 业务数据采集平台
NFT到底有哪些实际用途?
STP生成树(端口状态+端口角色+收敛机制 )|||| STP优化技术( uplinkfast技术+Portfast技术+backbonefast技术 )详解
AcWing 3391. 今年的第几天?(简单题)









