zoukankan      html  css  js  c++  java
  • PHP 学习1.3

    1.展示类的继承和静态的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>定义和调用函数</title>
    </head>

    <body>
    <?
      class Cart{
      var $items;
      function Cart(){
            $this->Say();
          }
      function addItem($product,$num){
           $this->items[$product]+=$num;
          }
      function reomveItem($product,$num){
            if($this->items[$product]>$num){
                 $this->items[$product]-=$num;
                 return true;
                }elseif($this->items[$product]==$num){
                    unset($this->items[$product]);
                    return true;
                }
              else{
                return false;
                }
          }
       function  ShowCart(){
             foreach($this->items as $k=>$v){
           echo "<br/> ".$k."=".$v;
          }
           }
       function Say(){
             echo "<br/> I'm Cart";
           }
       static    function  SayHello(){
               echo "<br/> Hello World!";
               }
          }
      class AutoCart extends Cart
      {
        function AutoCart(){
             $this->addItem("product1",1);
             $this->Say();
             }
        function ConstructCart($p="11",$n=2){
           $this->addItem($p,$n);
             }
        function Say(){
             echo "<br/> I'm AutoCart";
           }
      }
    Cart::SayHello();
    $cart = new AutoCart();
    $cart->ShowCart();
    $cart2=new Cart();
    $cart2->addItem("12",2);
    $cart2->ShowCart();

    ?>
    </body>
    </html>

  • 相关阅读:
    Redis基本概念、基本使用与单机集群部署
    Storm安装部署
    HBase单机和集群版部署
    Hive基础概念、安装部署与基本使用
    Hadoop — HDFS的概念、原理及基本操作
    随机森林
    深度学习入门: CNN与LSTM(RNN)
    word修改页眉使本页的页眉与别的页不一样
    几个值得学习的Java博客
    【转】求最短路径长度--简单易懂
  • 原文地址:https://www.cnblogs.com/linsu/p/3473404.html
Copyright © 2011-2022 走看看