返回创建数组,并分......登陆

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

日日新2019-03-06 14:16:11256

<?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>";
}

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送