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


HACK1949

Recommended Posts

php:输出关联数组特定范围的数据

 

 

 

 

一、php源码(将“关联数组”转化为“索引数组”,然后输出)

 

 1 <?php
 2     
 3     // define data structure
 4     class SCOPE
 5     {
 6         private $scp_start="";
 7         private $scp_end="";
 8         
 9         public function set_start($scp_start)
10         {
11             $this->scp_start=$scp_start;
12         }
13         
14         public function get_start()
15         {
16             return $this->scp_start;
17         }
18         
19         public function set_end($scp_end)
20         {
21             $this->scp_end=$scp_end;
22         }
23         
24         public function get_end()
25         {
26             return $this->scp_end;
27         }
28     }
29     
30     
31     // print array,  $array_var = index array
32     function print_array($scope_var, $array_var)
33     {
34         for($st=$scope_var->get_start(); $st!=$scope_var->get_end(); $st++)
35         {
36             echo "array[$st]_out = " . $array_var[$st] . PHP_EOL; 
37         }
38     }
39     
40     
41     
42     // define relation array
43     $array_laohu=array("bg"=>"book1", 2=>"book2", 3=>"book3", 4=>"book4", "ed"=>"book5");
44     
45     // translate array; relation_array  ->  index_array
46     $array_translate = array_values($array_laohu);
47     
48     // define scope variable and set its values.
49     $sc = new SCOPE;
50     $sc->set_start(0);
51     $sc->set_end(6);
52     
53     // print array in the scope
54     print_array($sc, $array_translate);
55     
56     
57     
58 ?>

 

 

 

 

 

二、运行结果

 

 

1524989-20220816130944366-1822845937.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...