Adding PHP5 array functions for Router to basics

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4085 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-12-08 08:59:35 +00:00
parent 51e7c5e08c
commit b51bf20390

View file

@ -1207,6 +1207,57 @@
return I18n::translate($msg, null, $domain, null, null, $dir);
}
}
/**
* Computes the difference of arrays using keys for comparison
*
* @param array
* @param array
* @return array
*/
if (!function_exists('array_diff_key')) {
function array_diff_key() {
$valuesDiff = array();
if (func_num_args() < 2) {
return false;
}
foreach (func_get_args() as $param) {
if (!is_array($param)) {
return false;
}
}
$args = func_get_args();
foreach ($args[0] as $valueKey => $valueData) {
for ($i = 1; $i < func_num_args(); $i++) {
if (isset($arg[$i][$valueKey])) {
continue 2;
}
}
$valuesDiff[$valueKey] = $valueData;
}
return $valuesDiff;
}
}
/**
* Computes the intersection of arrays using keys for comparison
*
* @param array
* @param array
* @return array
*/
if (!function_exists('array_intersect_key')) {
function array_intersect_key($arr1, $arr2) {
$res = array();
foreach($arr1 as $key=>$value) {
if(array_key_exists($key, $arr2)) {
$res[$key] = $arr1[$key];
}
}
return $res;
}
}
/**
* @deprecated
* @see Set::countDim