Consider this:
If you have $array:
Array ([phil] => 'full', [mary] => 'partial', [bob] => 'partial', [joe] => 'full');
I need to replace every single key in $array, which will be unique, with the values of $array2:
Array ([phil] => 'blahblahblah', [mary] => 'thequickbrownfox', [bob] => 'bob', [joe] => 'helloworld');
I can't use array_flip() because the values are never always unique, I can't use array_invert() (in the PHP Manual see link) because it miscreates the array..
if (!function_exists('array_invert')) {
/**
* Invert an array without losing duplicate values (behavior of array_flip() function)
*
* @access public
* @param array $array
* @return array $res
* @link [url]http://us2.php.net/manual/en/function.array-flip.php#50651[/url]
* @see link regarding usage of "array_invert" function
*/
function array_invert($array) {
$res = Array();
foreach(array_keys($array) as $key) {
if (!array_key_exists($array[$key], $res)) $res[$array[$key]] = Array();
array_push($res[$array[$key]], $key);
}
return $res;
}
}
@reset($userPrivilegeArray); @reset($userPasswordArray);
if (is_array($userPrivilegeArray) && @sizeof($userPrivilegeArray) > 0 && is_array($userPasswordArray) && @sizeof($userPasswordArray) > 0) {
$userKeyArray = array_invert($userPrivilegeArray);
print_r($userKeyArray); echo "\n";
array_walk($userKeyArray, create_function('&$a', '$a = $userPasswordArray[$a];'), $userPasswordArray);
$userPrivilegeArray = array_invert($userKeyArray);
print_r($userPrivilegeArray); echo "\n";
}
Any bright ideas?
Thanx
Phil