我有已转换为数组的字符串,但想在列表中显示它们。如何重置循环以避免重复?我试过将变量设置为空白,通常用于单个foreach语句$SEAT = "1A,4A";$NAME = "John Doe, Jane Doe";$PHONE_NUMBER = "123456856,1235668";$SEAT_USSD_STRING_VALUE = explode(",", $SEAT);$NAME_USSD_STRING_VALUE = explode(",", $NAME);$PHONE_USSD_STRING_VALUE = explode(",", $PHONE_NUMBER);$seat_value = "";foreach ($SEAT_USSD_STRING_VALUE as $seat_key => $seat_value) { $name_value = ""; foreach ($NAME_USSD_STRING_VALUE as $name_key => $name_value) { $phone_number_value = ""; foreach ($PHONE_USSD_STRING_VALUE as $phone_number_key => $phone_number_value) { echo "$seat_value: $name_value - $phone_number_value<br/>"; } }}我期望得到1A: John Doe - 123456784A: Jane Doe - 87654321但是我得到这个1A: John Doe - 123456781A: John Doe - 876543211A: Jane Doe - 123456781A: Jane Doe - 876543214A: John Doe - 123456784A: John Doe - 876543214A: Jane Doe - 123456784A: Jane Doe - 87654321
3 回答
LEATH
TA贡献1936条经验 获得超6个赞
您只需要使用第$seat_key一个可访问的键()foreach
用这个foreach代替你所有的foreach
foreach ($SEAT_USSD_STRING_VALUE as $seat_key => $seat_value) {
echo "$seat_value: $NAME_USSD_STRING_VALUE[$seat_key] - $PHONE_USSD_STRING_VALUE[$seat_key]<br/>";
}
- 3 回答
- 0 关注
- 265 浏览
添加回答
举报
0/150
提交
取消