PHP file deduplication, two-dimensional array filtering

Source: Internet
Author: User

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

-----------Target will be repeated on the left side---

Http://www.porter.com/fr/fr/product/648162|Sneakers
http://www.porter.com/fr/fr/product/642115| [Email protected] [Email Protected]@[email protected]

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

<?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 (' 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))//Search $v[$key] is present in the $tmp_arr array, if there is a return true
{
echo "Print_r ($v [$key]);
Print_r ($tmp _arr); echo "---Unset ($arr [$k][0]);
}
else {
$tmp _arr[] = $v [$key];
}
}
Sort ($arr); Sort function sorting an array
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);

PHP file deduplication, two-dimensional array filtering

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.