update page now
Longhorn PHP 2026 - Call For Papers

Voting

: five plus two?
(Example: nine)

The Note You're Voting On

fantomx1 at gmail dot com
9 years ago
Since array_walk cannot modify / change / reindex keys as already mentioned, i provide this small wrapping function which accomplishes passing array reference and index using closures , "use" keyword.

function indexArrayByElement($array, $element)
{
    $arrayReindexed = [];
    array_walk(
        $array,
        function ($item, $key) use (&$arrayReindexed, $element) {
            $arrayReindexed[$item[$element]] = $item;
        }
    );
    return $arrayReindexed;
}

<< Back to user notes page

To Top