Created
July 9, 2012 14:24
-
-
Save boh1996/3076857 to your computer and use it in GitHub Desktop.
Array mix php
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 | |
/** | |
* 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, <[email protected]> | |
*/ | |
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