当前位置:网站首页>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);
边栏推荐
猜你喜欢
随机推荐
selenium IDE的3种下载安装方式
uni-app 顶部选项卡吸附效果 demo(整理)
固件工程师到底是干什么?
判断根节点是否等于子节点之和
【论文笔记】一种基于启发式奖赏函数的分层强化学习方法
LINGO 18.0 software installation package download and installation tutorial
Exception: Dataset not found.解决办法
Scala parallel collections, parallel concurrency, thread safety issues, ThreadLocal
并发之固定运行和交替运行方案
Guava-字符串工具
10分钟带你入门chrome(谷歌)浏览器插件开发
编程踩坑合集
并发之多把锁和活跃性
计算机网络之网络安全
【论文笔记】基于动作空间划分的MAXQ自动分层方法
The window of the chosen data flow
QImage的指针问题
scala 并行集合、并行并发、线程安全问题、ThreadLocal
10 minutes to get you started chrome (Google) browser plug-in development
IDEA的database使用教程(使用mysql数据库)