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 Laravel 4 Basics Project Setup Further Into Routing

Further Into Routing Quiz

The quiz asks: Which of the following is not a valid way to pass a parameter into a view? I knew the other two options were correct, so I selected:

return View::make('home', ['data' => $data]);

That answer was incorrect. The lecture video showed arrays constructed using array(). Is this answer just another way of writing:

return View::make('home', array('data' => $data));

I probably just don't remember passing arrays in that manner. As I recall, you just pass the variable. For example, if you have:

$myArray = ['name' => 'jane', 'email' => 'jane@doe.com']

then you simply pass $myArray as function($myArray), not function(['name' => 'jane', 'email' => 'jane@doe.com'])). Hence, my confusion. So to summarize, are both forms acceptable for passing an aray?

2 Answers

Starting with PHP 5.4, you can use a shorthand notation for Arrays. In version prior to 5.4 an array was defined like so:

$myArray = array('data' => $data);

With PHP 5.4+ you can use [] notation:

$myArray = ['data' => $data];

Laravel I believe is built on PHP 5.4+ so you will see notation that utilizes more of the recent changes to PHP.

Thanks. I've already been through all the PHP courses in the PHP track. I don't know what version is being taught, but I really don't remember seeing that new notation. If it's not there, it should not have been on this quiz because it certainly wasn't in the lecture. Maybe there is an assumption that anyone taking the Laravel course will always be using the latest version of PHP.