-
-
Save vkdimitrov/7047335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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