-1

我有这个 php 代码,我很确定它没问题。但是$category 变量没有被重写,即即使$category 是'251',if 循环也不会执行为真。

任何想法为什么?

foreach($cars->cardata as $cardata ){

    $category = $cardata->categorie;

    if($category == '251'){
        $category = 'BWM';
    }

    echo $category;
}
4

1 回答 1

1
foreach($cars->cardata as $cardata ){

    $category = $cardata->categorie;

    if(trim($category) == '251'){
        $category = 'BWM';
    }

    echo $category;
}
于 2012-05-24T21:17:59.023 回答