本文主要是介绍CakePHP v3.9.3 Array,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.Apace start
2.
array.php
C:\xampp\htdocs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello</title>
</head>
<body>
<h1><?="Calculate" ?></h1>
<?php
$total=0;
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$n = count($data);
for($i = 0; $i < $n;$i++){
$total +=$data[$i];
}
$average = $total/$n;
?>
<p><?='Total is : ' . $total .' and Average is : ' . $average?></p>
</body>
</html>
3.
http://localhost/array.php
另一种遍历数组的方法
array.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello</title>
</head>
<body>
<h1><?="Calculate" ?></h1>
<?php
$total=0;
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$n = count($data);
foreach($data as $item){
$total +=$item;
}
$average = $total/$n;
?>
<p><?='Total is : ' . $total .' and Average is : ' . $average?></p>
</body>
</html>
这篇关于CakePHP v3.9.3 Array的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!