Last active
August 29, 2015 14:24
-
-
Save pkostadinov-2create/ba62bd9538cc2ffbd7fa to your computer and use it in GitHub Desktop.
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 | |
$a = array('rund' => '2', 'group' => '3', 'kupon' => 'utre', 'tralala' => 'shtur_kupon'); | |
$b = array('grund' => '2', 'group' => 'ww', 'soup' => '1', 'tralala' => 'fd'); | |
function two_arrays_merge_all_values(array $a, array $b) { | |
foreach ($b as $b_key => $b_value) { | |
$last_index_a = count($a)-1; | |
$current_index = 0; | |
foreach ($a as $a_key => $a_value) { | |
if ($a_key === $b_key) { | |
$unique = uniqid(); | |
$a[$b_key . '_' . $unique] = $b[$b_key]; | |
unset($b[$b_key]); | |
break; | |
} | |
if ($current_index == $last_index_a) { | |
$a[$b_key] = $b[$b_key]; | |
unset($b[$b_key]); | |
} | |
$current_index++; | |
} | |
} | |
return $a; | |
} | |
$result = two_arrays_merge_all_values($a, $b); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment