我正在尝试使用 foreach 循环显示 2 个数组,但由于某种原因,当数组中的值设置为 0 时,仅显示数组的最后一项
假设我有以下数组值:
users array ( 0 => user1, 1 => user2)
occurrences array ( 0 => 0, 1 => 3) //the key represents the user from the users array
foreach 循环的输出将正确显示
//output
user1 0
user2 3
但是,如果两个值都为 0,则只会显示 user2
users array ( 0 => user1, 1 => user2)
occurrences array ( 0 => 0, 1 => 0); //the key represents the user from the users array
//output (should also display user1 0)
user2 0
这是我的 foreach 循环。
?>
<table>
<th>User</th><th># of Occurrences</th>
<?
foreach (array_combine($occurrences, $users) as $occur => $user){
?>
<tr><td><? echo $user; ?></td><td><? echo $occur; ?></td></tr>
<?
}
?></table>
<?