Earlier this year, I wrote about how my patch for
array_column() was merged into the development branch for PHP 5.5 in preparation for the beta release. I received a lot of great feedback and many kind words. Then, on June 20, the PHP team announced the general availability version of 5.5.0. With that,
array_column() was released to the world for general use.
Many still use earlier versions of PHP, though. While the functionality of
array_column() is simple enough to implement on your own in userland code, I’ve released a small library that implements it in userland code exactly as it’s implemented in the core, complete with the same PHP error messages and warnings. The library is also upgrade-proof, so when you start running your projects on PHP 5.5+, you’ll immediately take advantage of the built-in, core
array_column() function, rather than the library—without the need to modify your code.
The library has no dependencies and has been tested on PHP 5.3 and 5.4. The library’s unit tests also pass with the core version of
array_column() in PHP 5.5. Additionally, the library passes the phpt core tests for the function.
To use the library in your projects, simply download the source code and include
src/array_column.php where you need to use it. Alternately (and recommended), the library supports installation via Composer. You may add it to your project requirements by running this command:
composer.phar require rhumsaa/array_column:~1.1
Optionally, you may directly update your
composer.json with the following:
1 2 3 4 5
Check out the project on Github, and I hope you enjoy using