Are arrays implicitly created in PHP when one of i

2019-06-24 10:38发布

Just wishing to quickly verify this. It is different from my immediate experience from other languages whereby an array must first be declared before it can be filled with values.

3条回答
做个烂人
2楼-- · 2019-06-24 11:18

$array['one'] = "one". Is this what your asking? Because yes, this will create a new array

查看更多
Rolldiameter
3楼-- · 2019-06-24 11:33

PHP will create the array even without being implicitly declared, yes.

$array[] = ...

$array would be a valid array.

查看更多
神经病院院长
4楼-- · 2019-06-24 11:37

Yes, PHP will automatically create an array given any of the following

$foo[] = $bar;
$foo[1] = $bar;
$foo['bar'] = $bar;

// and of course
$foo = array();

// and soon to pass
$foo = [1, 2, 3];
查看更多
登录 后发表回答