Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Basics (Retired) PHP Datatypes PHP Datatypes Challenge

Short array syntax support

When asked to create an empty array $colors

$colors = [];

the short array syntax is not accepted as a valid answer.

2 Answers

In PHP the correct syntax to make an empty array would be $colors = array(); PHP doesn't use the "[ ]" for arrays like other languages do.

From PHP dpcumentation "As of PHP 5.4 you can also use the short array syntax, which replaces array() with []."

<?php

$normal_array = array();
$short_array = [];

echo gettype($normal_array);
// => array

echo gettype($short_array);
// => array

var_dump($normal_array);
// => array(0) {}

var_dump($short_array);
// => array(0) {}

?>

Hi Sergio,

I don't know how the challenge works. I'm not sure if it's running the code in a live php environment but perhaps the version is lower than php 5.4 which is when that became available.

Hampton Paulk Should the challenge pass with the short array syntax?