- 论坛徽章:
- 0
|
基本语法
1:
c:\AppServ\www\phptest\class\class01.php
http://localhost/phptest/class/class01.php
1: color=$c ;
6: }
7: function get_color(){
8: return $this->color ;
9: }
10: }
11:?>
12:
13: 物件
14:
15: set_color("宝蓝色") ;
18: echo "车子的颜色是" . $MyCar->get_color() ;
19: ?>
20:
21:
c:\AppServ\www\phptest\class\class02.php
http://localhost/phptest/class/class02.php
1:item[]=$name ;
7: $this->item[]=$cost;
8: }
9: function GetItem(){
10: $c=count($this->item);
11: for ($i=0; $iitem[$i];
13: echo " => 金额 : ".$this->item[$i+1]." 元
";
14: }
15: }
16: function sum() {
17: $c=count($this->item);
18: $s=0;
19: for ($i=1; $iitem[$i];
21: }
22: return $s;
23: }
24: }
25:?>
26:
27:物件应用
28:
29:AddOneItem("主机板","3000") ;
33: $customer1->AddOneItem("显示卡","800") ;
34: $customer1->AddOneItem("记忆体","1800") ;
35: $customer2->AddOneItem("PC游戏","2500") ;
36: $customer2->AddOneItem("滑鼠","100") ;
37: $customer2->AddOneItem("无线网路卡","2500") ;
38: $customer2->AddOneItem("LCD显示器","8000") ;
39: echo "第一位顾客采购内容:
";
40: $customer1->GetItem();
41: echo "" ;
42: echo "第二位顾客采购内容:
";
43: $customer2->GetItem();
44: echo "";
45: $total=$customer1->sum()+$customer2->sum();
46: echo "今日营业额 $total 元";
47:?>
48:
49:
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/108609/showart_2127437.html |
|