php:面向对象之成员变量(数组)
一、PHP源码
1 <?php 2 3 class DATA{ 4 public $dlt_data = ""; 5 6 // set value of $dlt_data by ARRAY 7 function set_array_value($array_type) 8 { 9 $this->dlt_data = $array_type; 10 } 11 12 // set value of '$DATA->dlt_data' by key and value. 13 function set_key_value($key, $value) 14 { 15 $this->dlt_data[$key]=$value; 16 } 17 } 18 19 20 function display_data($DATA_type) 21 { 22 foreach($DATA_type->dlt_data as $k=>$v) 23 { 24 echo $k . " => " . $v . PHP_EOL; 25 } 26 } 27 28 29 $DATA_object = new DATA; 30 $array_laohu = array("elem1"=>"gold", "elem2"=>"wood", 3=>"water"); 31 32 $DATA_object->set_array_value($array_laohu); 33 $DATA_object->set_key_value("elem5", "earth"); 34 35 //set value of '$DATA_object->dlt_data' by another way. 36 $DATA_object->dlt_data["elem4"] = "fire"; 37 38 display_data($DATA_object); 39 40 ?>
二、PHP源码的运行结果
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280778.html