An alternative way for PHP array_column

As a developer i'm pretty much sure, most of the developers use latest version of PHP in their machine, so do I. 

The thing is, sometime with version of PHP on hosting servers, we have to think about the alternative way.

Here with this post I am going to share a pro tip for developers,  I learned when i also got stuck with.


Alternative way for to make it working on old version of PHP for method  array_column , this method is available only on (PHP 5 >= 5.5.0, PHP 7) see official doc 

$array = [
   ['developer' => ['name' => 'Sujip Thapa', 'age' => 25, 'expericence' => '+3 years']],
   ['developer' => ['name' => 'Aakash Gurung', 'age' => 25, 'expericence' => '+3 years']],

In PHP >=5.5 get all developers name only:

$developers = array_column($array, 'name');

In PHP < 5.5 - alternative way to get all developers name only:

$developers = array_map(function ($each) {

 return $each['name'];

 }, $array);

If you are a Laravel developer and using v4.2 you also can do like below, see official doc

$developers = array_fetch($array, 'name');

Output will be same:

$developers = ['Sujip Thapa', 'Aakash Gurung'];

Happy Coding !