初识php2

来源:互联网 发布:印象笔记 数据迁移 编辑:程序博客网 时间:2024/04/29 19:30
<?php/** * Created by PhpStorm. * User: dllo * Date: 16/8/8 * Time: 下午3:39 */header("Content-type:text/html;charset=utf-8");if (1){    echo "是";}else{    echo "否";}echo "<hr>";//awitch(){//    case ://        break;//}// 100,每天花一半,计算多少天花完/* $a = 0;for ($i = 100; $i > 1; $i/=2){    $a = $a + 1;}echo $a;echo "<hr>";$j = 100;$b = 0;while($j> 1){    $b += 1;    $j /= 2;}echo $b;echo "<hr>";$money = 100;$day = 1;for(; $money/2 >= 1; $day++){    $money = $money/2;}echo $day;echo "<hr>";while($money/2 >= 1){    $day++;    $money = $money / 2;}echo $day;*/// 变量作用域// 1.全局变量$i = 0;function test0($a){    // 默认函数内取不到全局变量,需要加global声明    global $i;    return $i + $a;}// 2.局部变量function test(){    // 函数内的变量为局部变量    $a = 20;}// 3.静态变量// 初始化1次,之后这个变量的值一直保留static $b = 5;function test1(){    static $c = 3;    $c++;    return $c;}test1();test1();echo test1();echo "<hr>";function cheng($i){    if ($i == 1){        return 1;    }else{        return cheng($i - 1) * $i;    }}echo cheng(5);echo "<hr>";function pay($money){    static $day = 1;    if ($money/2 < 1){        return $day;    }else{        $day++;        return pay($money/2);    }}echo pay(100);echo "<hr>";function huiWen($str){    static $i = 0;    $half = strlen($str)/2;    if ($str[$i] != $str[$half*2 - 1 - $i]){        return false;    }else{        $i++;        if ($i < $half){            return huiWen($str);        }else{            return true;        }    }}// 函数名不区分大小写var_dump(huiWen("abccba"));// 函数
0 0