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 !
Written by Kuldeep
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#