define("PI",3.14);//空格打习惯了,逗号后面不要有空格,虽然运行正确的,但还是会报错
define($p,3.14);
define($p,3.14);
2018-04-12
在PHP中foreach循环语句,常用于遍历数组,一般有两种使用方式:不取下标、取下标。
(1)只取值,不取下标
<?php
foreach (数组 as 值){
//执行的任务
}
?>
(2)同时取下标和值
<?php
foreach (数组 as 下标 => 值){
//执行的任务
}
?>
(1)只取值,不取下标
<?php
foreach (数组 as 值){
//执行的任务
}
?>
(2)同时取下标和值
<?php
foreach (数组 as 下标 => 值){
//执行的任务
}
?>
2018-04-08
foreach($students as $r=>$v){
echo "ID:$r--";
echo "姓名:$v";
echo "<br />";
}
echo "ID:$r--";
echo "姓名:$v";
echo "<br />";
}
2018-04-08
$sum = 12;
$max = 1000;
$n = 0;
echo "我饿啦:-(";
echo "<br />";
while($sum<$max){
$num = rand(1,100);
$sum = $sum + $num;
$n = $n+1;
echo $n.".增加饱食度".$num."点,当前饱食度[".$sum."/".$max."]";
echo "<br />";
}
echo "终于吃饱啦^_^";
$max = 1000;
$n = 0;
echo "我饿啦:-(";
echo "<br />";
while($sum<$max){
$num = rand(1,100);
$sum = $sum + $num;
$n = $n+1;
echo $n.".增加饱食度".$num."点,当前饱食度[".$sum."/".$max."]";
echo "<br />";
}
echo "终于吃饱啦^_^";
2018-04-08