且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 删除重复的 XML 提要条目

更新时间:2021-08-16 09:31:24

只需将这些对放在一个数组中,使用标题作为键,链接作为值.插入数组时,您只需覆盖重复项.

Just put those pairs in an array, use title as key, link as value. You would simply override duplicates when inserting into the array.

请参阅此问题,了解有关 Java 哈希图和 PHP 的讨论数组.

See this question for a discussion about Java hashmaps and PHP arrays.

像这样:

$a = array("one" => "one_link", "two" => "two_link", "one" => "one_link");

$target = array();

foreach ($a as $key => $value)
   $target[$key] = $value;

这会让你:

array("one" => "one_link", "two" => "two_link")

使用此设置,无需检查密钥是否已存在.

With this setup, there is no need to check if the key already exists.