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

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.