PHP基础介绍

php之基本操作

1.常用数据类型:
  字符串、整形、浮点数、逻辑、数组、对象、NULL。
  字符串: $x = "hello";
  整形:$x = 123;
  浮点数:$x =1.123;
  逻辑: $x = true;
  数组: $x = array(1,2,3,4,5)
  对象: class
  NULL: $x = NULL

2.PHP算数运算符:
  +(加法)、-(减法)、*(乘法)、/(除法)、%(取余)
  串接:
    $txt1 = "hello";
    $txt2 = $txt1." world!";
  串接赋值:
    $txt1 = "hello";
    $txt1 .= " world!";
  自增、自减:
    ++$x; (加完返回x)
    $x++; (先返回x再加)
    --$x; (减完返回x)
    $x--; (先返回x再减)

3.赋值方式:
  x = x + y、x= x - y、x = x * y、x = x / y 、x = x % y

4.PHP比较运算符:
  == 等于
  === 全等
  != 不等于
  <> 不等于
  !== 不全等(完全不等)
  > 大于
  < 小于
  >= 大于等于
  <= 小于等于

5.PHP 逻辑运算符
  and(与)、or(或)、xor(异或)、&&(与)、||(或)、!(非)

6.PHP 数组运算符
  +(联合)、==(相等)、===(全等)、!=(不相等)、<>(不相等)、!==(不全等)

7.PHP之Switch语句
  switch(expression){
  case label1:
    expression = label1时执行的代码;
    break;
  case label2:
    expression = label2时执行的代码;
  default:
    表达式的值不等于label及不等于label2时执行的代码;
  }
  工作原理:
    1.对表达式(通常是变量)进行一次计算
    2.把表达式的值与结构中 case 的值进行比较
    3.如果存在匹配,则执行与 case 关联的代码
    4.代码执行后,break 语句阻止代码跳入下一个 case 中继续执行
    5.如果没有 case 为真,则使用 default 语句

8.PHP之文件操作:
  全部读取:
    $file = fopen("t.text", "r");
    echo fread($file, filesize("t.text"));
    fclose($file);
    输出单个字符直到end-of-file:
    $file = fopen("t.text", "r");
    while (!feof($file)) {
      echo fgetc($file);
    }
    fclose($file);
  文件写入:
    $file = fopen("t.text","w+");
    $str = "hello world!";
    fwrite($file,$str);
    echo "ok";
    fclose($file)

原文地址:https://www.cnblogs.com/yaoxiaofeng/p/10596603.html