I have two arrays, one is keys and second is values. I want combine together in foreach loop, but i'm failed to create logic. Please see code i hope you will understand what i exactly want?
$keys = Array ( [0] => name [1] => qualification [2] => Major Subject [3] => Matric [4] => Conferred Date: [5] => Attendance From: [6] => Attendance To: [7] => AK [8] => AK [9] => AK )
$values = Array ( [0] => ayaz [1] => matric [2] => Chemistry [3] => Olevel [4] => 2015-08-12 [5] => 2015-08-22 [6] => 2015-08-14 [7] => AK [8] => AK [9] => AK )
I want to combine it in foreach loop and set as key value. So please guide me how can do this. Thanks in advanced.
I have tried this but failed to get better result
foreach(array_map(null, $savvion_key, $savvion_value) as $combined) {
print_r($combined);
}
Try this way
foreach ($keys as k => v ) {
print_r( v . ' ' . $value[k]);
}
Solution1:
function array_merge_keys($ray1, $ray2) {
$keys = array_merge(array_keys($ray1), array_keys($ray2));
$vals = array_merge($ray1, $ray2);
return array_combine($keys, $vals);
}
Solution2:
<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);
print_r($c);
?>
The above example will output:
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)