Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

php:面向对象之成员变量(数组)

 Share


Recommended Posts

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源码的运行结果

 

 

1524989-20220816012846747-759768330.png

 

 

 

 

 

Link to post
Link to comment
Share on other sites

 Share

discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...