在函数中声明数组调用PHP


Declare Array Inside Function Call PHP

嘿,我想知道除了array()之外,是否有更简单的方法在函数调用中声明数组

$setup = new setupPage();
$setup->setup(array(
                   type => "static",
                   size => 350
                 ));
class setupPage {
    public function setup($config){
        echo $config[size] . $config[type];
    }
}

谢谢:D

如果您使用PHP 5.4+,您可以使用简写,但是它在性能上没有区别,但实际上可能使其更难阅读:

$setup->setup(['type' => 'static',
               'size' => 350]);

用下面的代码创建一个数组(student)的PHP程序分类:student_id, student_name, student_address,Student_state、student_zip和student_age。内部函数程序将接受所有值并限制数据类型每个都通过了。该函数创建数组并放置值放入数组中。显示数组中的值。使用try/catch如果其中一个或多个值不是正确的数据类型