面向对象的哲学.wmv 课程预习笔记
1 <?php 2 class student 3 { 4 var $no; 5 var $name; 6 var $gender; 7 var $age; 8 9 function set_data($arr) 10 { 11 $this->no=$arr["no"]; 12 $this->name=$arr["name"]; 13 $this->gender=$arr["gender"]; 14 $this->age=$arr["age"]; 15 16 17 } 18 19 function grow($i){ 20 $this->age+=$i; 21 } 22 function get_data(){ 23 echo"<br /> 24 <b>学生信息</b><br /> 25 "; 26 echo "学号:$this->no<br /> 27 ";echo "姓名:$this->name<br /> 28 ";echo "性别:$this->gender<br /> 29 ";echo "年龄:$this->age<br /> 30 "; 31 } 32 } 33 $s=new student; 34 $temparr=array("no"=>"001","name"=>"lisa","gender"=>"male","age"=>"22"); 35 $arr=array("no"=>"001","name"=>"lisa","gender"=>"女性","age"=>"31"); 36 37 $s->set_data($temparr); 38 $s->get_data(); 39 $s->grow(2); 40 $s->get_data(); 41 42 43 ?>
结果:
学生信息
学号:001
姓名:lisa
性别:male
年龄:22
学生信息
学号:001
姓名:lisa
性别:male
年龄:24