当我对10个数组使用foreach()并使用if(variable = something){}else{}来显示我想从其中得到什么时,我在php上遇到了一些问题。
否则将返回所有内容10倍。
我需要帮助的是,当6111或6112不存在时,它只显示一次我在else{}中拥有的内容,而不是显示它10倍,因为有10个数组。
foreach(){
if($statplayemasteriesslotsID == 6111){
//dothis
} else if($statplayemasteriesslotsID == 6112){
//dothis
} else {
//dothis
}
}有这样的事吗?
我也尝试过这样做,用if{} else {}作为前端,但是它不是多次返回所有内容,而是将它们混合在一起。
foreach(){
if($statplayemasteriesslotsID == 6111){
$statplayemasteriesslotsID1 = 6111;
} else if($statplayemasteriesslotsID == 6112){
$statplayemasteriesslotsID1 = 6112;
}
}
if($statplayemasteriesslotsID1 == 6111){
//dothis
} else if($statplayemasteriesslotsID1 == 6112){
//dothis
} else {
//dothis
}我目前正在使用的最后一种方式,如果有人知道停止这件事,请告诉我。提前感谢
发布于 2016-12-23 01:50:38
我会这么做:
$doC = false;
foreach(){
if($statplayemasteriesslotsID == 6111){
//dothis
} else if($statplayemasteriesslotsID == 6112){
//dothis
} else {
//don't do it yet, just set a flag:
$doC = true;
}
}
if($doC) {
// do it once only!
}https://stackoverflow.com/questions/41294119
复制相似问题