我在变量$comments
中有一个多维数组,包含:
Array (
[0] => Array
(
[0] => 889
[1] => First comment
[2] => 8128912812
[3] => appr
)
[1] => Array
(
[0] => 201
[1] => This is the second comment
[2] => 333333
[3] => appr
)
// There is more...
)
如何遍历此数组并使用每个值回显每个值?
答案 0 :(得分:3)
foreach($arrayOfArrays as $array){
foreach($array as $index => $value){
echo $array[$index];
}
}
答案 1 :(得分:2)
您应该使用两个foreach
循环,因为您的数组必须具有级别:
foreach ($comments as $comment)
foreach ($comment as $comment_data)
echo $comment_data;
答案 2 :(得分:1)
如果您的阵列结构与您显示的阵列结构类似,则可以执行以下操作:
foreach($comments as $comment) {
echo $comment[0];
echo $comment[1];
echo $comment[2];
echo $comment[3];
}
答案 3 :(得分:0)
只需使用两个foreach循环。一个在另一个内部
foreach($comments as $commentArray){
foreach($commentArray as $comment){
echo $comment;
}
}
希望这有助于你
答案 4 :(得分:0)
$i=0;
$c=count($array);
while ($i<$c) {
foreach ($array[$i] as $comment_property) {
echo $comment_property;
}
$i++;
}