Update:
As of PHP 5.4.0 a shortened syntax for declaring arrays has been introduced:
$list = [];
Previous Answer:
There isn't. Only $list = array();
But you can just start adding elements.
<?php
$list[] = 1;
$list['myKey'] = 2;
$list[42] = 3;
It's perfectly OK as far as PHP is concerned. You won't even get a E_NOTICE for undefined variables.
E_NOTICE level error is issued in case
of working with uninitialized
variables, however not in the case of
appending elements to the
uninitialized array.
As for shorthand methods, there are lots scattered all over. If you want to find them just read The Manual.
Some examples, just for your amusement:
$arr[]
shorthand for array_push
.
- The
foreach
construct
echo $string1, $string2, $string3;
- Array concatenation with
+
- The existence of
elseif
- Variable embedding in strings,
$name = 'Jack'; echo "Hello $name";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…