perl - Does PHP have autovivification? -


searching php.net autovivification gives no results. @ time of writing, wikipedia claims perl has it. there no definitive results when searching google "php autovivification".

this php code runs fine:

$test['a'][4][6]['b'] = "hello world"; var_dump($test);  array   'a' =>      array       4 =>          array           'b' =>              array               ... 

can provide canonical answer (preferably references) php have feature, , details such version introduced in, quirks, shortcuts etc?

yes, php have autovivification (and has had long time), although isn't referenced terminology. php.net states:

an existing array can modified explicitly setting values in it.

this done assigning values array, specifying key in brackets. key can omitted, resulting in empty pair of brackets ([]).

$arr[key] = value; $arr[] = value; // key may integer or string // value may value of type 

if $arr doesn't exist yet, created, alternative way create array.

however, documentation states if try access value of unset array (or key), return error:

attempting access array key has not been defined same accessing other undefined variable: e_notice-level error message issued, , result null.

i have tracked down old php3 manual, states this:

you can create array adding values array.

$a[] = "hello"; 

Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -