php - Combine 2 arrays of different length -
i have array 100 values(array1). have array 8 values(array2). want take values array2 , use them keys , extract values in array1 keys.
the array_combine function won't work of different lengths.
i have tried
function array_combine2($arr1, $arr2) { $count = min(count($arr1), count($arr2)); return array_combine(array_slice($arr1, 0, $count), array_slice($arr2, 0, $count)); }
but doesn't work.....this gives me array correct keys, values incorrect, think because slicing array1.
could give assistance. there fair amount of literature on already, know, give solutions similar 1 above isn't working.
many time have taken.
something one:
function combine($array1, $array2) { $array3 = array(); foreach ($array2 $key => $value) { //loop through entries of array2 //get entry of array1 corresponds value of array2's entry if (isset($array1[$value]) { $array3[$key] = $array1[$value] } } return $array3; }
i haven't tested should give thought.
Comments
Post a Comment