php:输出关联数组特定范围的数据
2022/8/16 14:53:30
本文主要是介绍php:输出关联数组特定范围的数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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 ?>
二、运行结果
这篇关于php:输出关联数组特定范围的数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善