我們在操作數據庫的時候,需要用到下面我們看一個基本的數字格式的數組遍歷:
- <?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關聯數組在數據庫中的相關使用方法。