php - Shorthand for arrays: is there a literal syntax like {} or []? -
what shorthand array notation in php?
i tried use (doesn't work):
$list = {};
it perfect, if give links on information other shorthands php.
update:
of php 5.4.0 shortened syntax declaring arrays has been introduced:
$list = [];
previous answer:
there isn't. $list = array();
can start adding elements.
<?php $list[] = 1; $list['mykey'] = 2; $list[42] = 3;
it's ok far php concerned. won't e_notice undefined variables.
e_notice level error issued in case of working uninitialized variables, not in case of appending elements uninitialized array.
as shorthand methods, there lots scattered over. if want find them read the manual.
some examples, amusement:
$arr[]
shorthandarray_push
.- the
foreach
construct echo $string1, $string2, $string3;
- array concatenation
+
- the existence of
elseif
- variable embedding in strings,
$name = 'jack'; echo "hello $name";
Comments
Post a Comment