PHP关联数组的具体使用方法
我们在操作数据库的时候,需要用到PHP关联数组,它会给我们带来许多好处。我们今天就向大家具体介绍PHP关联数组的一些使用方法,希望对有需要的朋友有所帮助。
- 分析PHP函数array_pop()的具体使用方式
- PHP函数array_shift()在删除数组元素中的
- PHP数组转换的具体代码编写介绍
- PHP常用字符串的大集合
- PHP接收复选框信息的简便方法讲解
- <?php
- $temp[0] = "richmond";
- $temp[1] = "tigers";
- $temp[2] = "premiers";
- for($x=0;$x<count($temp);$x++)
- {
- echo $temp[$x];
- echo " ";
- }
- ?>
然而另外一种更加节省代码的方式是:
- <?php
- $temp = array("richmond", "tigers", "premiers");
- foreach ($temp as $element)
- echo "$element ";
- ?>
foreach 还能输出文字下标:
- <?php
- $temp = array("club" => "richmond",
- "nickname" =>"tigers",
- "aim" => "premiers");
- foreach ($temp as $key => $value)
- echo "$key : $value ";
- ?>
以上就是PHP关联数组在数据库中的相关使用方法。
PHP之友评论