查看: 4541|回复: 0

[PHP学习] php入门之数组(1)

发表于 2018-4-10 08:00:04

/
数组:在一个变量中,存储一个或多个值,每一个元素都有一个访问ID
foreach($arr as $key=>$value)
/
$arr = array('李海','PHP视频教程','29','1982-05-08');
//print_r($arr);
//echo "学员名是:".$arr[0]." 所学课程:".$arr[1]." 年龄:".$arr[2]." 生日:".$arr[3];
$arr1 = array("uname"=>"江梅","uclass"=>"DIV+CSS","age"=>"44","birth"=>"1958-08-11");
//print_r($arr1);
//echo "年龄:".$arr1['age']."出生日期:".$arr1['birth'];
$arr2 = array(array("uname"=>"李满","age"=>"15"),array("uname"=>"小海","age"=>"38"));
echo "

";
//print_r($arr2);
//echo $arr2[1]["uname"];
$arr3["网站名称"]="后盾网";
$arr3["课程"]="php教程";
$arr3["课时"]="300课时";
//print_r($arr3);
$arr4[]="PHP课程";
$arr4[]="网站标准布局课程";
//print_r($arr4);
$arr5["PHP"]=array();
$arr5["PHP"]['cname']="php课程";
$arr5["PHP"]['ctime']="300课时";
$arr5["DIV"]=array();
$arr5["DIV"]['cname']="DIV+CSS课程";
$arr5["DIV"]['ctime']="100课时";
$arr5['HTML']="HTML基础知识如TABLE,IFRAME课程";
$arr5['JAVASCRIPT']="js知识,jqery课程";
//print_r($arr5);

/*
foreach($arr3 as $k=>$value){

if($k == "课程"){
echo $k. "".$value."";
}else{
echo $k.$value;
}

}
/
/

foreach($arr5 as $key => $value){
echo "

";
if(is_array($value)){
echo $key.":
";
foreach($value as $k=>$v){
echo " ".$k."=>".$v."";
}
}else{
echo $key."=>".$value;
}
echo "
";
}
/
/

foreach($arr5 as $key => $value){
echo "
";
if(is_array($value)){
echo $key.":
";
echo "课程名:".$value['cname']." 课时:".$value['ctime'];

}else{
echo $key."=>".$value;
}
echo "

";
}
/
$db = new mysqli('localhost','root','123456','edu') or die('连接错误');
$db->query("set names gbk");
$sql ="select
from user";
$result = $db->query($sql);
echo "";
while($row = $result->fetch_assoc()){
echo "";
echo "";
echo "";
}
echo "
学员名:{$row['uname']}课程名:{$row['cname']}
";



回复

使用道具 举报