src/helpers/ArrayHelper.php
public static function assoc_to_keyval($assoc, $keyField, $valField)
    {
        if (!is_array($assoc) and ! $assoc instanceof Iterator) {
            throw new InvalidArgumentException('The first parameter must be an array.');
        }
        $output = [];
        foreach ($assoc as $row) {
            if (isset($row[$keyField]) and isset($row[$valField])) {
                $output[$row[$keyField]] = $row[$valField];
            }
        }
        return $output;
    }
public static function assoc_to_keyval($assoc, $keyField, $valField)
    {
        if (!is_array($assoc) and ! $assoc instanceof Iterator) {
            throw new InvalidArgumentException('The first parameter must be an array.');
        }
        $output = [];
        foreach ($assoc as $row) {
            if (isset($row[$keyField]) and isset($row[$valField])) {
                $output[$row[$keyField]] = $row[$valField];
            }
        }
        return $output;
    }
public static function assoc_to_keyval ( $ assoc , $ keyField , $ valField ) { if ( ! is_array ( $ assoc ) and ! $ assoc instanceof Iterator ) { throw new InvalidArgumentException ( 'The first parameter must be an array.' ) ; } $ output = [ ] ; foreach ( $ assoc as $ row ) { if ( isset ( $ row [ $ keyField ] ) and isset ( $ row [ $ valField ] ) ) { $ output [ $ row [ $ keyField ] ] = $ row [ $ valField ] ; } } return $ output ; }
Converts a multi-dimensional associative array into an array of key => values with the provided field names.
@param   array   $assoc    the array to convert.
@param   string  $keyField the field name of the key field.
@param   string  $valField the field name of the value field.
@return  array
@throws  InvalidArgumentException
Converts a multi - dimensional associative array into an array of key = > values with the provided field names .