Blogger Information
Blog 9
fans 0
comment 0
visits 6027
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0127循环,替代语法 文本包含
蔡威
Original
593 people have browsed it

运算符

  1. $a = 10;
  2. printf('++$a =%d ,$a= %d <br>', ++$a, $a); //++$a =11 ,$a= 11
  3. printf('$a++ =%d ,$a= %d <br>', $a++, $a); //$a++ =11 ,$a= 12
  4. printf('2的4次方%d <br>', 2 ** 4); //次幂 2的4次方16
  5. $a = 1;
  6. $b = 2;
  7. $a += $b; //$a=3 , $b = 2
  8. $a -= $b; //$a=1 , $b = 2
  9. $a .= $b; //$a=12 , $b = 2 字符串拼接

太空船

  1. $a = 10;
  2. $b = 8;
  3. if ($a > $b):
  4. echo 1;
  5. elseif ($a = $b):
  6. echo 0;
  7. elseif ($a < $b):
  8. echo -1;
  9. endif;
  10. echo "<br>";
  11. echo $a <=> $b;

替代语法 前大括号 换成 : 后大括号换成 endforeach

  1. if ($i>=10):
  2. echo "比十大";
  3. elseif($i<10):
  4. echo "比十小";
  5. elseif ($i == 0):
  6. echo "为零";
  7. endif;

循环

入口循环
初始值 循环条件 更新循环条件

  1. //初始值 $i=0
  2. //循环条件 $i<count($arr)
  3. //更新循环条件 $i++
  4. $i = 0;
  5. $arr = ["北京", "上海", "长春", "纽约"];
  6. while ($i < count($arr)):
  7. if ($i == 1) {
  8. $i++; //如果在while中使用中断,不要忘记更新循环条件
  9. continue;//跳出本次循环
  10. }
  11. printf("%s<br>", $arr[$i]);
  12. $i++;
  13. endwhile;
  14. var_dump($arr);

北京
长春
纽约
array(4) { [0]=> string(6) “北京” [1]=> string(6) “上海” [2]=> string(6) “长春” [3]=> string(6) “纽约” }
出口循环

  1. $i = 0;
  2. do {
  3. printf("%s<br>", $arr[$i]);
  4. $i++;
  5. } while ($i < count($arr));

foreach 可以遍历数组 和对象

foreach循环与字符串拼接

for遍历关联数组

遍历关联数组

include 和 require

include 导入不成功继续下面代码 require 不会继续
运行mysql

  1. //config.php
  2. <?php
  3. // 返回值
  4. return [
  5. 'type' => 'mysql',
  6. 'host' => 'localhost',
  7. 'dbname' => 'mysql',
  8. 'username' => 'root',
  9. 'password' => 'cckyd123',
  10. ];
  11. //connect.php
  12. <?php
  13. // 连接数据库
  14. // 引入连接参数配置文件
  15. $config = require 'config.php';
  16. // print_r($config);
  17. extract($config);
  18. $pdo = new PDO("$type:host=$host;dbname=$dbname;", $username, $password);
  19. if ($pdo) {
  20. echo '<h2>连接成功</h2>';
  21. }

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post