我有一个 php 文件,其中通过 simplexml 加载 xml 文件并搜索相应的 id,一切正常,但是当将 id 与给定的匹配时,它不起作用,如果我回显它们,它们会显示,但如果我使用 if 语句来匹配它们不会匹配
这是我的php代码
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$cat_xml= simplexml_load_file('http://artstack.com/sites/77/site_categories.xml');
$product_xml= simplexml_load_file('http://artstack.com/sites/77/site_products.xml');
function getcatid($product_name,$product_xml){
foreach($product_xml as $product){
if($product){
if($product_name==$product->url){
return $product->cat_id;
}
}
}
}
function getcat($cat_id,$cat_xml){
foreach($cat_xml as $cat){
if($cat){
if($cat_id==$cat->id){
echo $cat['name'];
}
else{
if(isset($cat->category)){
//sub cat
foreach($cat->category as $subcat){
if($subcat){
echo $cat_id." > ".$subcat->id."<br>";
if($cat_id==$subcat->id){
echo $cat_id." > ".$subcat->id."<br>";
exit;
}
}
}
}
}
}
}
}
getcat(getcatid($_GET['pro'],$product_xml),$cat_xml);
?>
输出是
75 > 73
75 > 74
75 > 75
但它必须是
75 > 73
75 > 74
75 > 75
75 > 75