php 二维数组 筛选,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:[email protected][email protected]@[email protected]

$strs = file("cat.txt");

$strs = array_map(‘trim‘,$strs);

$strsc = count($strs);

for($i=0;$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 "


--";

//print_r($v[$key]);

//print_r($tmp_arr);echo "---


";

unset($arr[$k][0]);

}

else {

$tmp_arr[] = $v[$key];

}

}

//sort($arr); //sort函数对数组进行排序

return $arr;

}

//print_r("

"); 
 

//print_r(assoc_unique($keyexplode,0));

$keyexplodenew = assoc_unique($keyexplode,0);

//print_r($keyexplodenew);

for($j=0;$j

{

// print_r($j);

// print_r($keyexplodenew[$j]);

if(isset($keyexplodenew[$j][0]))

{

echo "
".$keyexplodenew[$j][0].‘|‘;

//array_merge($keyexplodenew[$j], $keyexplodenew[$j-1]);

}

else{echo [email protected];}

echo $keyexplodenew[$j][1];

}

//print_r($keyexplodenew);

原文:http://www.cnblogs.com/alex-13/p/4742590.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值