Skip to content

Instantly share code, notes, and snippets.

@kresnasatya
Last active May 3, 2018 03:37
Show Gist options
  • Save kresnasatya/eab0d569923914ec8a9657822376973e to your computer and use it in GitHub Desktop.
Save kresnasatya/eab0d569923914ec8a9657822376973e to your computer and use it in GitHub Desktop.
Combine arrays without key
<?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