PHP数组和explode()函数应用实例,供大家学习参考。
例1:
<?php
$province = array("北京","上海","天津","重庆","河北","山西","内蒙古","辽宁","吉林","黑龙江","江苏","浙江","安徽","福建","江西","山东","河南","湖北","湖南","广东","广西","海南","四川","贵州","云南","西藏","陕西","甘肃","宁夏","青海","新疆","香港","澳门","台湾","其他");
echo count($province);//数组成员个数
echo "<br/>";
if(is_array($province)){//检测变量是否是数组
echo "嗯,真是个数组啊";
}
echo "</br>";
for($index=0;$index<count($province);$index++){//数组循环
echo $province[$index];
echo "</br>";
}
?>
例2:
<?php
//利用 explode 函数分割字符串到数组
$source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++){
echo $hello[$index];echo "</br>";
}
?>
例3:
//函数挺实用的
// 分隔符可以是斜线,点,或横线
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
php中Mysqli多个查询的例子,感兴趣的朋友可以参考下。
mysqli_multi_query(mysqli link,string query) 连续执行多次查询,是基于过程的
msyqli_more_results(mysqli link) 主要确定返回的结果集是否有其他的结果集
mysqli_next_result(mysqli link) 获取下一个结果集
举例:
#连接数据库
$link=mysqli_connect("localhost","root","root");
#选择数据库
$link->select_db("rorely") or die("could not find database");
#查询数据库
if($link->multi_query("select * from test;select name ,age ,sex,address from test")){
do{
$result=$link->store_result();
while($row=$result->fetch_row()){
echo "$row[0],$row[1],$row[2],$row[3]<br>";
}
if($link->more_results()) echo "**********<br>";
}while($link->next_result());
}
$link->close();
?>
结果如下:
1,Jane,26,female
3,Tome,21,male
4,Lily,25,female
5,Lucy,25,female
6,Jim,22,male
7,Jim,22,male
**********
Jane,26,female,wenming cun 123#
Tome,21,male,wenming cun 32#
Lily,25,female,wenming cun 2#
Lucy,25,female,wenming cun 2#
Jim,22,male,wenmin cun 45#
Jim,22,male,wenmin cun 45#
li,22,female,wenming cun 23#
hj,30,male,wenming cun 23#
hj,30,male,wenming cun 23#
php mysqli扩展库的例子:
#连接数据库
$link=mysqli_connect("localhost","root","root");
#选择数据库
$link->select_db("rorely") or die("could not find database");
#查询数据库
$result=$link->query("select * from test");
#输出数据库表各个记录的内容
while($row=mysqli_fetch_object($result)){
echo $row->id." ".$row->name." ".$row->age." ".$row->sex." ".$row->address."<hr>";
}
#关闭数据库
mysqli_close($link);
?>
结果:
1 Jane 26 female wenming cun 123#
3 Tome 21 male wenming cun 32#
4 Lily 25 female wenming cun 2#
5 Lucy 25 female wenming cun 2#
6 Jim 22 male wenmin cun 45#
7 Jim 22 male wenmin cun 45#
您可能感兴趣的文章:
linux下为php添加扩展库的方法
PHP添加CURL扩展库的二种方法
php mysqli扩展库之预处理操作的二个例子
php mysqli扩展库操作mysql的例子