Code array() With [ ] Square Brackets

As of PHP 5.4 you can also use short array syntax, which replaces array() with [ ] square brackets.

Example:

The 1st example codes the array function for 2 custom post types named listing and portfolio using array().

array( 'listing','portfolio' );

You can now code the array using square brackets like this:

['listing','portfolio'];

If you’re learning PHP, at some stage you’ll come across PHP code which codes arrays using square brackets.

Related Tutorials

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.