Returns values for a specific array and key This PHP (5.3) code is intended to take an array and a key as inputs, and return an array of the values paired with that key‡

function valuelist($array, $array_column) {
    $return = array();
    foreach($array AS $row){
        $return[]=$row[$array_column];
    };
    return $return;
};


Can this be improved in terms of processing speed?

‡-For example, given:

$get_role_action = array(
    array("ACTION_CD" =&gt; "RETURN_PETITION"),
    array("ACTION_CD" =&gt; "UNLOCK_RECORD"),
    array("ACTION_CD" =&gt; "ACKNOWLEDGE"),
    array("ACTION_CD" =&gt; "REQUEST_POST_ACTION"),
    array("ACTION_CD" =&gt; "CHANGE_REQUEST_TYPE")
);


$variables['role_action_list']=valuelist($get_role_action, 'ACTION_CD'); should yield:

["role_action_list"]=&gt;
    array(17) {
    [0]=&gt;
    string(15) "RETURN_PETITION"
    [1]=&gt;
    string(13) "UNLOCK_RECORD"
    [2]=&gt;
    string(11) "ACKNOWLEDGE"
    [3]=&gt;
    string(19) "REQUEST_POST_ACTION"
    [4]=&gt;
    string(19) "CHANGE_REQUEST_TYPE"
}
I was able to play around with your requirements, and I think I got a solution.

Here is what I did to profile your code.

I set up the data array with:

$new = array(
    array('a' =&gt; 1,
        'b' =&gt; 2),
    array('a' =&gt; 3,
        'b' =&gt; 4),
    array('a' =&gt; 5,
        'b' =&gt; 6),
);


Calling it like so:

valuelist($new, 'b');


to produce:

Array
(
    [0] =&gt; 2
    [1] =&gt; 4
    [2] =&gt; 6
)


And the average function time was about 2.1894 E-6 seconds.

However, PHP 5.5 introduced us to the array_column function! And it happens to do exactly what you want! Yipee!

We can do a big swap-out, and come up with this:

function valuelist($array, $array_column) {
    return array_column($array, $array_column);
}


Now when we do the 50k calls, we learn that now the average function time is about 2.6226 E-10 seconds.

However, there is a little overhead due to the user function applied over top of the built-in function. By just calling array_column without the function does reduce the processing time, but by an amount so small it's hard to even say it's an amount! Just for the sake of cleanliness, I'd remove the user function anyways.

Don't tell me that's not an improvement!

However, without this function, I was unable to get a faster execution. I tried array_filter, array_map, and array_walk. Using use for the closure, as that proved faster than array_map's third parameter.