src/Traverser.php
public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
    {
        $result = [];
        foreach ($arr as $key => &$value) {
            // Run the callback and store the result in a variable so that we allow the key to be modified by the
            // callback. Also pass the original array if one needs to unset variables from the original array.
            $r = $itemCallback($value, $key, $arr);

            // Store the item callback's result with the (new) key.
            $result[$key] = $r;
        }

        if (!is_null($resultCallback)) {
            // Allow for the original array to be modified with the result array.
            return $resultCallback($result, $arr);
        }

        return $result;
    }
public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
    {
        $result = [];
        foreach ($arr as $key => &$value) {
            // Run the callback and store the result in a variable so that we allow the key to be modified by the
            // callback. Also pass the original array if one needs to unset variables from the original array.
            $r = $itemCallback($value, $key, $arr);

            // Store the item callback's result with the (new) key.
            $result[$key] = $r;
        }

        if (!is_null($resultCallback)) {
            // Allow for the original array to be modified with the result array.
            return $resultCallback($result, $arr);
        }

        return $result;
    }
public static function run ( array & $ arr , callable $ itemCallback , callable $ resultCallback = null ) { $ result = [ ] ; foreach ( $ arr as $ key => & $ value ) { // Run the callback and store the result in a variable so that we allow the key to be modified by the // callback. Also pass the original array if one needs to unset variables from the original array. $ r = $ itemCallback ( $ value , $ key , $ arr ) ; // Store the item callback's result with the (new) key. $ result [ $ key ] = $ r ; } if ( ! is_null ( $ resultCallback ) ) { // Allow for the original array to be modified with the result array. return $ resultCallback ( $ result , $ arr ) ; } return $ result ; }
Runs the traverser across the given array and executes the item callback into every item of the array.

The traverser also has a result callback to allow for 'macro' result processing.

@param array    $arr            The array to traverse.
@param callable $itemCallback   The item callback to operate into every item.
Callback signature used:
- array function($value, $key, $arr) { }
@param callable $resultCallback The result callback to operate into the result array.
Callback signature used:
- mixed function($resultArray, $originalArray) { }

@return array Returns the resulting array.
Runs the traverser across the given array and executes the item callback into every item of the array .