1,html代码+php代码混写

  <div style="overflow:hidden;border:1px solid #f75730;width:960px;height:50px;margin:0px auto 10px;">
        <?php
            echo "111111111111<br/>1111111<br/>1111";
         ?>
    </div>

2,php向前台输出html代码+数组遍历
    <?php
        echo '<div style="overflow:hidden;border:1px solid #f75730;width:960px;height:80px;margin:0 auto;">';
        $cars=array("Volvo","BMW","SAAB");  //php数组
        echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
        echo "<br/>";
        for($i=0;$i<count($cars);$i++)  //遍历数组
        {
            echo $cars[$i];
            echo "<br/>";
        }
        echo '</div>';
    ?>

3,foreach数组遍历
    <?php
        echo '<div style="overflow:hidden;border:1px solid #f75730;width:960px;height:80px;margin:0 auto;">';
        $age=array("Bill"=>"35","Steve"=>"37","Peter"=>"43");

        foreach($age as $x=>$x_value) {
          echo "Key=" . $x . ", Value=" . $x_value;
          echo "<br>";
        }
        echo '</div>';
  ?>

4,运算符运算,函数,类

  <?php
    ini_set('date.timezone','Asia/Shanghai');
    echo "1,算数运算<br/>";
    $a = 8;
    $b = 2;
    $c = 3;
    echo $a+$b."<br>\n";  //10
    echo $a-$b."<br>\n";  //6
    echo $a*$b."<br>\n";  //16
    echo $a/$b."<br>\n";    //4
    echo $a%$c."<br>\n";  //2
    
    echo "<br/>2、字符串运算<br/>";
    //字符串运算 (string operator) 的运算符号只有一个,就是英文的句号 .。它可以将字符串连接起来,变成合并的新字符串。
    $a = "PHP 4";
    $b = "功能强大";
    echo $a.": ".$b;  //PHP 4:功能强大

    echo "<br/><br/>3、赋值运算<br/>";
    $a = 5;
    $a += 2;    // 即 $a = $a + 2; 7
    echo $a."<br>\n";   //7
    $b = "哇";
    $b .= "哈";   // $b = "哇哈";
    $b .= "哈";   // $b = "哇哈哈";
    echo "$b<br>\n";  //哇哈哈
    
    
    echo "<br/><br/>5、其他运算符<br/>";
    //echo date("Y");
    ?>
    © 2010-<?php echo date("Y")?>
    <!--
    在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个
    "PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings.
    You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
    In case you used any of those methods and you are still getting this warning, you most likely
    misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in"
    这样的错。如何解决呢?
    @三种解决方法:
    一、在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC'); //东八时区 echo date('Y-m-d H:i:s');
    二、在页头使用 ini_set('date.timezone','Asia/Shanghai');
    三、修改php.ini。打开php5.ini查找date.timezone 去掉前面的分号修改成为:date.timezone =PRC,经检测第三种方法还会报错!!!
    -->
    
    <?php
    echo "<br/>6,switch运算符";
    $Day="Wed";
    switch ($Day) {
    case "Mon":
        echo "今天星期一";
        break;
    case "Tue":
        echo "今天星期二";
        break;
    case "Wed":
        echo "今天星期三";
        break;
    case "Thu":
        echo "今天星期四";
        break;
    case "Fri":
        echo "今天星期五";
        break;
    default:
        echo "今天放假";
        break;
    }
    ?>
    <?php
        echo "<br/>7,函数";
        /*函数名不区分大小写,所以需要保证唯一性。PHP函数支持传值和传址两种传参方式。
        传址是为了在执行函数的同时改变函数参数的只,而传值不期望改变。*/
        /*
        下边是函数原型,在实际应用中,不能这样声明。
        function myfunc($arg_1, $arg_2, ...,$arg_n) {
            // 执行一些步骤
            return $retval;
        }
        */
    ?>
    
    
    <?php
    /* 不使用默认值 */
    function myfunc($arg_1, $arg_2, $arg_3="我是默认字符串") {
      echo $arg_1+$arg_2;
      echo $arg_3."<p>\n";
    }
    
    echo "<br/><br/>";
    /* 使用默认值 */
    myfunc(3, 4);               // 参数 $arg_3 省略。  输出:7 我是默认字符串
    myfunc(6, 6, "不用默认值")  // 输入参数 $arg_3。   输出:12 不用默认值
    ?>
    
    <?php
        echo "<br/>8,类";
        /*PHP 只有类别 (class)、方法 (method)、属性、以及单一继承 (extensions) 等。
          下面的范例是手推车类。可以看到,使用class表示它是一个类类别。在类别中的 function,
        例如 add_item 则表示该类的一个方法。方法可以封装类的实际处理情形,让该类自己能依封装好的方法来执行一些步骤。*/
    ?>

posted on 2016-12-27 08:08  学到老死  阅读(170)  评论(0)    收藏  举报