我想在foreach循环中显示多维数组。
$result = mysql_query("SELECT * FROM `marvin`.`moje`;");
$i = 0;
while($row = mysql_fetch_array($result)){
$sql[$i] = array($row['id'], $row['name'], $row['price'], $row['material']);
$i++;
}
如何写循环现在多维数组$sql[$i]
?我真的想用foreach循环。请不要写while循环
谢谢。
就像这样简单:
foreach ($sql[$i] as $sqld) {
echo $sqld;
}
所以应该是这样的:
$result = mysql_query("SELECT * FROM `marvin`.`moje`;");
$i = 0;
while($row = mysql_fetch_array($result)){
$sql[$i] = array($row['id'], $row['name'], $row['price'], $row['material']);
foreach ($sql[$i] as $sqld) {
echo $sqld;
}
$i++;
}
如果你想在while循环之外显示它:
foreach ($sql as $sqli) {
foreach ($sqli as $sqld) {
echo $sqld;
}
}