PHP数组解包
<?php // php_version = 7.4.1 // phpinfo(); class array_object { private array $array_obj = []; public function set_array(array $k=[]){ $this -> array_obj = $k; } public function get_array(){ return $this->array_obj; } public function display_array(){ echo "array :="; foreach($this->array_obj as $key=>$value){ echo " $value"; } echo " ".PHP_EOL; } } function print_array(array $in){ echo "array :="; foreach($in as $key=>$value) { echo " $value"; } echo " " . PHP_EOL; } // 创建“array_object”实例 $tmp = new array_object(); $tmp -> set_array(["Gou", "TianQiao", "QiChe"]); // 数组解组 “...array_name” $tmp_in = ["Wukong", ...$tmp->get_array() ]; // 显示数组数据 print_array($tmp_in); ?>
输出结果:
// 输出结果 array := Wukong Gou TianQiao QiChe