php - get array of particular keys from multidimensional array without foreach loop

php
voted: 0
vote
php array array-map

This code will get array of particular key from another array with array_map function.

<?php
    $colors = array(
        array(
            'id' => 1,
            'name' => 'green'
        ),
        array(
            'id' => 2,
            'name' => 'orange'
        ),
        array(
            'id' => 3,
            'name' => 'yellow'
        )
    );

    $colorNames = array_map(function ($ar) {
        return $ar['name'];
    }, $colors);
    ?>
working url: not entered
version: 5.3 and higher
Leave a Comment:
Characters left:
No comments yet.