Feature Request #4398

Preserve keys in Arr::pluck()

Added by Ivan Petropolsky almost 3 years ago.

Status:NewStart date:01/11/2012
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution: Points:1

Description

Like this:

public static function pluck($array, $key, $preserve_keys = false)
{
    $values = array();

    foreach ($array as $i => $row)
    {
        if (isset($row[$key]))
        {
            // Found a value in this row
            if ($preserve_keys)
            {
                $values[$i] = $row[$key];
            }
            else
            {
                $values[] = $row[$key];
            }
        }
    }

    return $values;
}

Also available in: Atom PDF