News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Setfive.com:
PHP Some thoughts on using array_* with closures
March 19, 2013 @ 10:36:22

On the Setfive site there's a recent post from Ashish Datta about some thoughts around array functions and closures for callback methods.

The other day, I was hacking away on the PHP backend for the "Startup Institute" visualization and I realized it was going to need a good deal of array manipulation. Figuring it was as good a time as any, I decided to try and leverage PHP 5.3+ new closures along with the array_* functions to manipulate the arrays. I'm not well versed with functional programming but I've used Underscore.js's array/collection functions so this is mostly in comparison to that.

He gives a sample data set he's pulling from - basic user data - and goes through a few different actions that can be taken on the data (with code examples for each): sorting, mapping and filtering. He shows the use of closures as the callback methods instead of defining them separately and passing in their names.

0 comments voice your opinion now!
array closure callback example


blog comments powered by Disqus

Similar Posts

Script-Tutorials.com: Vimeo API - OAuth and Upload Example

Juozas Kaziukenas' Blog: Service Layer in Web applications

ProDevTips: Sorting 2D-arrays in PHP - anectodes and reflections

CodeIgniter Blog: New Site Enhancements

Jani Hartikainen's Blog: Closures coming in PHP 5.3 and thatís a Good Thing


Community Events

Don't see your event here?
Let us know!


series community php7 voicesoftheelephpant api library laravel unittest example security opinion interview introduction laravel5 video version framework podcast language release

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework