Last active
May 3, 2018 03:37
-
-
Save kresnasatya/eab0d569923914ec8a9657822376973e to your computer and use it in GitHub Desktop.
Combine arrays without key
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_arrays($arrays) { | |
$results = array(); | |
foreach ($arrays as $subKey => $arr) { | |
foreach ($arr as $index => $key) { | |
$results[$index][$subKey] = $arr[$index]; | |
} | |
} | |
return $results; | |
} | |
$names = array('Bob', 'Fred', 'Joe', 'X', null); | |
$emails = array('[email protected]', '[email protected]', '[email protected]', null); | |
$ids = array(1,2,3,4); | |
$result_x = combine_arrays(array('name' => $names, | |
'email' => $emails, | |
'id' => $ids)); | |
echo"<pre>";print_r($result_x);echo"</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment