php文件去重复,二维数组筛选

http://www.porter.com/fr/fr/product/648162|Sneakers
http://www.porter.com/fr/fr/product/642115|Boots
http://www.porter.com/fr/fr/product/642115|Flat_Shoes
http://www.porter.com/fr/fr/product/642115|Pumps
http://www.porter.com/fr/fr/product/642115|Sandals
http://www.porter.com/fr/fr/product/642115|Sneakers

-----------目标 将|左侧重复的变成---

http://www.porter.com/fr/fr/product/648162|Sneakers
http://www.porter.com/fr/fr/product/642115|Boots@Flat_Shoes@Pumps@Sandals@Sneakers

=====================================================================

<?php
$strs = file("cat.txt");
$strs = array_map('trim',$strs);
$strsc = count($strs);
for($i=0;$i<$strsc;$i++)
{
$keyexplode[] = explode('|',$strs[$i]);
}
//$keyexplodet = array(array('184007', "Flat_Shoes" ), array('184007', "Pumps" ), array('184008', "Sandals" ));
function assoc_unique($arr, $key)
{
$tmp_arr = array();
foreach($arr as $k => $v)
{
if(in_array($v[$key], $tmp_arr))//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
{
//echo "<hr/>--";
//print_r($v[$key]);
//print_r($tmp_arr);echo "---<hr/>";
unset($arr[$k][0]);
}
else {
$tmp_arr[] = $v[$key];
}
}
//sort($arr); //sort函数对数组进行排序
return $arr;
}
//print_r("<pre/>");
//print_r(assoc_unique($keyexplode,0));
$keyexplodenew = assoc_unique($keyexplode,0);
//print_r($keyexplodenew);
for($j=0;$j<count($keyexplodenew);$j++)
{
// print_r($j);
// print_r($keyexplodenew[$j]);
if(isset($keyexplodenew[$j][0]))
{
echo "<br/>".$keyexplodenew[$j][0].'|';
//array_merge($keyexplodenew[$j], $keyexplodenew[$j-1]);
}
else{echo '@';}
echo $keyexplodenew[$j][1];
}
//print_r($keyexplodenew);

 

posted @   也许明天  阅读(527)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
历史上的今天:
2013-08-19 magento head.phtml 加载<a target=_parent
点击右上角即可分享
微信分享提示