Possible Duplicate:
php values of one array to key of another array
i have given two array here.
Array-1
(
[0] => 6
[1] => 11
[2] => 13
)
Array-2
(
[0] => 13.339066309
[1] => 0
[2] => 100
)
I want to replace value of one array to key of another array. something like this:
Array
(
[6] => 13.339066309
[11] => 0
[13] => 100
)
Use array_combine
:
$new_array = array_combine($array1, $array2);
take a look at array_combine()
$result = array_combine(array_values($firstArr), array_values($secondArr));
Try this:
$result = array();
foreach ($array1 as $key => $value) {
$result[$value] = $array2[$key];
}
Try something like this
$t = array();
$keys = array_keys($arr1);
for ($i = 0; $i < min(count($keys), count($arr2)); $i++) {
$t[$keys[$i]] = $arr2[$i];
}