循环求数组中的值得和
$a = array(30,50,70,90);
$b=0;
foreach($a as $v){
$b+=$v;
}
echo '这个数组的值为'.$b;
效果相当于数组函数 array_sum(),数组函数我在https://blog.csdn.net/zyh2468/article/details/119535702?spm=1001.2014.3001.5501有总结
$a = array(30,50,70,90);
$b=array_sum($a);
echo '这个数组的值为'.$b;
循环输出信息到表格中
$arr = array(
array('name'=>'张三','age'=>37,'sex'=>'男'),
array('name'=>'张四','age'=>15,'sex'=>'男'),
array('name'=>'张五','age'=>18,'sex'=>'男'),
array('name'=>'张六','age'=>19,'sex'=>'男'),
array('name'=>'张七','age'=>20,'sex'=>'男'));
echo '<table width="800" border="1" >';
echo '<tr>';
echo '<th>name</th>';
echo '<th>age</th>';
echo '<th>sex</th>';
echo '</tr>';
foreach($arr as $value){
echo '<tr>';
foreach($value as $zhi){
echo '<th>';
echo $zhi;
echo '</th>';
}
echo '</tr>';
}
echo '</table>'
效果