I have keys array and values array.
$keys = [
0 => 'Test'
1 => 'John'
...
22 => 'Kate'
23 => 'Bob'
]
I run an array_filter($values) to clear out unwanted empty values, then I end up with something like this
$values = [
1 => '$3'
22 => '$10'
23 => '$50'
]
My goal is achieving
[
'John' => '$3',
'Kate' => '$10',
'Bob' => '$50'
]
Is there a way to map it this way without creating a for loop and a new array to assign each index individually?
I tried using array_intersect_key but couldn't get close at all.
Edit: My version looks like below but I'm sure there are better ways:
$selectedCols = array_intersect_key($keys, array_flip(array_keys($values)));
array_combine($selectedCols, $values);