创建数组,并分别用for while 和foreach遍历数组

Original 2019-03-06 14:16:11 252
abstract:<?php//索引数组$str=["亢龙有悔" ,"飞龙在天","龙兴日安心","县龙在天","潜龙勿用"];//关联数组$guanlian = ["name"=>"郭靖","position"=>"金岛驸马&q

<?php
//索引数组
$str=["亢龙有悔" ,"飞龙在天","龙兴日安心","县龙在天","潜龙勿用"];
//关联数组
$guanlian = ["name"=>"郭靖","position"=>"金岛驸马"."skill'=>'降龙第八章"];


$swean = [];
$swean["name"]="杨过";
$swean["position"]="daxia";
$swean["skill"]="xiaohunzhan";
echo $str[4];
echo  "<hr>";
//for 循环
$res1="";
for ($i=0;$i<count($str);$i++){
   $res1 .=$str[$i] .",";
}
echo $res1,"<hr>";
echo rtrim($res1,",");
echo "<hr>";
//while
$res2="";
$i=0;
while ($i<count($str)){
   $res2 .=$str[$i] ."*";
   $i++;
}
echo $res2,"<hr>";
echo rtrim($res2,"*");
echo "<hr>";
//foeeach
foreach ($guanlian as $key=>$value);
{
   echo $key, "=>" ,$value,"<hr>";
}

Correcting teacher:韦小宝Correction time:2019-03-06 15:41:30
Teacher's summary:写的很不错 foreach多用于数组的遍历 for很多地方都可以使用到 实际上for和while是没差的

Release Notes

Popular Entries