编程语言
首页 > 编程语言> > PHP:数组解包

PHP:数组解包

作者:互联网

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 

 

标签:tmp,function,解包,echo,value,数组,array,PHP
来源: https://www.cnblogs.com/lnlidawei/p/15657757.html