gpt4 book ai didi

php - 计算数组中的重复值

转载 作者:搜寻专家 更新时间:2023-10-31 20:42:42 27 4
gpt4 key购买 nike

使用以下代码计算值不会对我的数组产生任何结果。感谢您对我做错的任何帮助,谢谢。

$xml=simplexml_load_file("sitemap.xml");

$arr = array();
foreach($xml->url as $child)
{
if (isset($child->loc)) {
echo "true";
$arr[] = $child->loc;
} else {
echo "error";
echo $child->loc;
}
}
print_r(array_count_values($arr));

最佳答案

您必须正确地转换项目值,否则您将在数组中存储 SimpleXMLElement 对象:

$arr[] = (string)$child->loc;

关于php - 计算数组中的重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566969/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com