zoukankan      html  css  js  c++  java
  • PHP基本语句

    语句
    分支语句
    if语句
    if
    if.........else
    if.......else if.....else
    if 的嵌套
    switch语句

    循环语句

    for 循环

    函数

    函数的4要素::返回类型,函数名,参数,函数体

    1 //函数的定义方式
    2 function Show()
    3 {
    4     echo "hello";
    5 }
    6 //调用方式
    7 Show();
    1 //有参数的函数
    2 function Show($a,$b)
    3 {
    4     echo $a+$b;
    5 }
    6 Show(3,4)
    1 //有默认值的函数
    2 function Show($a=5,$b=5)
    3 {
    4     echo $a+$b;
    5 }
    6 Show();
     1 //参数可变的函数
     2 function Show()
     3 {
     4     $attr=func_get_args();//获取函数的参数
     5     $sum=0;
     6     for ($i=0;$i<count($attr);$i++)    //func_num_args() 获取参数的个数
     7     {
     8         $sum=$sum+$attr[$i];
     9     }
    10     echo $sum;
    1 //有返回值得函数
    2 function Show()
    3 {
    4     return "aaaa";
    5 }
    6 echo Show();
    1 //常用函数
    2 echo rand();                       //随机数生成函数
    3 echo time();                      //取当前的日期时间
    4 echo date("Y-m-d H:i:s",time());  //格式化日期时间
    5 echo strtotime("2015-05-06");     //将日期时间格式转化为时间戳
     1 //字符串处理函数
     2 $a = "hello";
     3 echo strlen($a);     //返回字符串的长度 ****
     4 echo strcmp("hello","aa");    //比较两个字符串是否相等   相等返回0,不相等返回1
     5 echo strcasecmp("hello","Hello");    //比较两字符串是否相等,不区分大小写
     6 strtolower("HELLO");     //将字符串转化为小写****
     7 strtoupper("hello");       //转化为大写
     8 $str="hello|world|join|on";
     9 var_dump (explode("|",$str));     //拆分字符串,返回数组。 ****
    10 $attr=array("aaa","bbb","ccc"); 11 implode("|",$attr); //将数组拼接成字符串 ****
    12 echo substr_replace($str,"aaa",0,5); //替换字符串(某个位置)**** 13 echo str_replace("l","a",$str); //查找替换**** 14 echo substr($str,0,5); //截取字符串****

    一些小知识点
    单引号和双引号都可以定义字符串
    1.双引号里可以使用转义字符,单引号里不能使用,会原样输出
    2.双引号里面可以解析变量,单引号不行

    1 //定义字符串(块)
    2 $str =<<<STR   //STR前不能有任何东西
    3 <div style="background:red; color:white; 100px;height:30px">hello</div>
    4 <div style="background:red; color:white; 100px;height:30px">world</div>
    5 STR;                   //STR前不能有任何东西
    6 echo $str;
  • 相关阅读:
    WPS设置去广告
    Android,几款apk工具
    Eclipse 使用
    linux su和sudo命令的区别
    CentOS下安装SecureCRT的sz/rz工具包
    CentOS下安装SecureCRT的sz/rz工具包
    CentOS下安装SecureCRT的sz/rz工具包
    VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
    修改CentOS系统的默认启动级别
    修改CentOS系统的默认启动级别
  • 原文地址:https://www.cnblogs.com/zk0533/p/5428279.html
Copyright © 2011-2022 走看看