Last Updated: February 25, 2016
·
2.161K
· mcraz

Getting an array index, the laravel way

I hate making code any complex than the simplest form it can take. That said, I am always looking for ways to make my code more readable.

Here is something I would normally do to output the value of a array item in view :

<?php echo isset($favourites['ide']) ? $favourite['ide'] : 'Sublime Text'; ?>

But after I fell in love with Laravel, it was just

{{ array_get($favourites, 'ide', 'Sublime Text') }}

Isn't life just simple now !