
public static void main(String[] args) throws Exception {
int[] intArray = new int[10]//新建一个int类型数组
for (int i = 0 i < 9 i++) {
intArray[i] = i
System.out.println("循环给int数组赋值,打印出来的值为 " + intArray[i])
}
}
}
运行结果为:
遍历数据表,把相应的数据放到数组中即可例如:
<?php
//定义一个数组,用于保存读取到的数据
$contents = array()
$query = mysql_query("select * from table")
//遍历数据表
while($array = mysql_fetch_array($query)){
$contents[] = $array
}
print_r($contents)
//然后循环数组,或者通过键名使用数组
foreach($contents as $value){
print_r($value)
}
echo $contents[0]['字段名称']
?>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)