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

objective c - Deep Linking for iOS Apps which are not installed yet? -

Java 8 + Maven Javadoc plugin: Error fetching URL -

java - Unable to publish my application to WAS 7.0.0.29 on RAD 7.5.5.5 iFix1 -