在我的foreach循环中,我希望在if语句之后不再输出IF中的项目。它不断回来......我该如何解决这个问题?
$content1 = "";
foreach($array as $key => $value) {
if(!empty($brandnid)) {
$content1 .= ',"' . $key . '":{"und":[{"nid":"[nid:' . $value . ']"}]}';
unset($array[array_search('field_brandid',$array)]);
}
$content1 .= ',"' . $key . '":{"und":[{"value":"' . $value . '"}]}';
}
if(!empty($title) && !empty($day) && !empty($month) && !empty($year)) {
$postContent = '{"type":"carmodels","title":"' . $title . '"' . $content1 . ',"field_modelyear":{"und":[{"value":{"date":"' . $dateBuild . '"}}]}}';
}elseif(!empty($day) && !empty($month) && !empty($year)) {
$postContent = '{"type":"carmodels","field_modelyear":{"und":[{"value":{"date":"' . $dateBuild . '"}}]}' . $content1 . '}';
}else {
$postContent = '{"type":"carmodels"' . $content1 . '}';
}
在上面的例子中,我输入了字段颜色(普通字段)和brandid,它在$ postContent中显示以下内容:
{"type":"carmodels","field_modelcolor":{"und":[{"nid":"[nid:black]"}]},"field_modelcolor":{"und":[{"value":"black"}]},"field_brandid":{"und":[{"nid":"[nid:24]"}]},"field_brandid":{"und":[{"value":"24"}]}}
但是它应该只在if语句中执行brandid(一次),然后才会在没有达到IF的正常字段中执行一次