Skip to content

Instantly share code, notes, and snippets.

@boh1996
Created July 9, 2012 14:24
Show Gist options
  • Save boh1996/3076857 to your computer and use it in GitHub Desktop.
Save boh1996/3076857 to your computer and use it in GitHub Desktop.
Array mix php
<?php
/**
* This function mixes two arrays together,
* taking the keys from one and the values from the other.
* This can be usefull when doing preq match,
* so the result can be accessed like this array["key"] => value in a situation like this,
* Message: My message could be accessed like this $matches["Message"]
* @param array $keys The array containing the keys to use
* @param type $values The array containing the values to use
* @return array
* @author Bo Thomsen, <bo@illution.dk>
*/
function array_mix ($keys, $values) {
$output = array();
foreach (array_values($keys) as $index => $key) {
$output[$key] = current(array_slice(array_values($values), $index, $index+1));
}
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment