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:

  1. $arr[] shorthand array_push.
  2. the foreach construct
  3. echo $string1, $string2, $string3;
  4. array concatenation +
  5. the existence of elseif
  6. variable embedding in strings, $name = 'jack'; echo "hello $name";

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -