Last Updated: February 25, 2016
·
1.708K
· Osvaldo Zonetti

PHP: Short syntax for arrays

Just letting you guys know that now you can do this:

$newSyntax = [
  'key' => 'value',
  'anotherKey' => 'anotherValue'
];

Instead of this:

$oldSyntax = array(
  'key' => 'value',
  'anotherKey' => 'anotherValue'
);

All you need is PHP 5.4 or higher.

For more info: https://wiki.php.net/rfc/shortsyntaxforarrays

2 Responses
Add your response

I think in this example is missing a '

$newSyntax = [
  'key' => 'value',
  'anotherKey' => 'anotherValue'
];
over 1 year ago ·

@bueltge True. Fixed. Thanks :D

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside