Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A function to rename keys from an array you provide.
<?php defined('SYSPATH') OR die('No direct script access.');
class Arr extends Kohana_Arr {
/**
* Maps new keys to an array
*
* Example:
*
* $customer_values = Arr::remap_keys($_POST, array(
* 'billing_address1' => 'address1', 'billing_address2' => 'address2'
* ));
*
* @param $values
* @param $new_keys
*
* @return array
*/
public static function remap_keys($values, $new_keys) {
$new_array = array();
foreach ($values as $key => $value) {
// if there is a new key to assign
if (array_key_exists($key, $new_keys)) {
$new_array[$new_keys[$key]] = $value;
} else {
$new_array[$key] = $value;
}
}
return $new_array;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.