Blogger Information
Blog 49
fans 0
comment 4
visits 41994
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
构造函数的使用
过儿的博客
Original
837 people have browsed it

构造函数的使用

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
   <?php
     class demo01{
         public $num;
         public $price;
         public function __construct($num,$price){
             $this->num = $num;
             $this->price = $price;
         }
         public function getMoney(){
             return '总共费用:'. $this->num*$this->price.'元';
         }
     }
     $obj = new demo01(2,36);
     echo $obj->getMoney();
   ?>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post