Created
May 3, 2018 03:36
-
-
Save kresnasatya/20637105adfd2727a1a778fb8d295bf9 to your computer and use it in GitHub Desktop.
Combine key with arrays
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 | |
function combine_keys_with_arrays($keys, $arrays) { | |
$results = array(); | |
foreach ($arrays as $subKey => $arr) | |
{ | |
foreach ($keys as $index => $key) | |
{ | |
$results[$key][$subKey] = $arr[$index]; | |
} | |
} | |
return $results; | |
} | |
$keys = array('u1', 'u2', 'u3'); | |
$names = array('Bob', 'Fred', 'Joe'); | |
$emails = array('[email protected]', '[email protected]', '[email protected]'); | |
$ids = array(1,2,3); | |
$result = combine_keys_with_arrays($keys, array('name' => $names, | |
'email' => $emails, | |
'id' => $ids)); | |
echo"<pre>";print_r($result);echo"</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment