background image

PHP+MYSQL 网站开发中遇到的问题汇总

  1. PHP 中数组的使用

  在操作数据库时,使用关联数组(associatively-indexed arrays)十分有帮助,下面我
们看一个基本的数字格式的数组遍历:

$temp[0] = "richmond";

                        

               $temp[1] = "tigers";

                        

               $temp[2] = "premiers";

                        
            
                        

               for($x=0;$x

                        

               {

                        

               echo $temp[$x];

                        

               echo " ";

                        

               }

                        

               ?>
然而另外一种更加节省代码的方式是:

  $temp = array("richmond", "tigers", "premiers");
  foreach ($temp as $element)
  echo "$element ";
  ?>
  foreach 还能输出文字下标:

$temp = array("club" => "richmond",

                        

               "nickname" =>"tigers",

                        

               "aim" => "premiers");

                        
            
                        

               foreach ($temp as $key => $value)

                        

               echo "$key : $value ";