Mecha CMS

Helper functions.

pluck

Extract member of array items by key and serve it as flat array.

2.2.0

pluck(array $data, string $key, $or = null);

Example:

$data = [
    [
        'value' => 'A',
        'id' => '41'
    ],
    [
        'value' => 'B',
        'id' => '42'
    ],
    [
        'value' => 'C',
        'id' => '43'
    ],
    [
        'value' => 'D',
        'id' => '44'
    ],
    [
        'value' => 'E',
        'id' => '45'
    ],
    [
        'value' => 'F',
        'id' => '46'
    ],
    [
        'id' => '47'
    ]
];

$A = pluck($data, 'value');
$B = pluck($data, 'value', '?');

Result:

$A = ['A', 'B', 'C', 'D', 'E', 'F', null];
$B = ['A', 'B', 'C', 'D', 'E', 'F', '?'];