【发布时间】:2015-02-09 14:20:25
【问题描述】:
我有一个已经存在值的数组:
$existingValues = array();
现在我在 xml 文件中获得了新值(是一个导入脚本),但我必须避免插入已经存在的值,我的问题是,如果我在 foreach 中列出所有来自 xml 的新值,我该怎么做?
$i = 1;
foreach($node->children() as $child) :
$attribute2 = $child->attributes();
$productcode = $attribute2['sku'];
$productvariant = $attribute2['variantid'];
$productprice = $attribute2['price'];
if ($attribute2['sku']) :
echo $productcode . ' - ' . $productvariant . '<br>';
endif;
$i++;
endforeach;
我尝试使用in_array(),但它不正确。
【问题讨论】:
-
你如何识别元素?我可以看到每个元素都有一些字段(
sku、variantid、price)。每个元素的id是多少?sku也许? -
啊抱歉,是的,我必须检查 sku,如果数组中的 sku 和 xml 中的 sku 相同,则忽略...
标签: php if-statement foreach