I am trying to create a new array from two current arrays. Tried array_merge but it wont give me what i want. $array1is a list of keys that I pass to the function. $array2contains the results of this function, but does not contain any keys available for keys. Therefore, I want to make sure that all requested keys are returned with zero values: ed, as shown in the array shown $result.
This is a bit like this:
$array1 = array('item1', 'item2', 'item3', 'item4');
$array2 = array(
'item1' => 'value1',
'item2' => 'value2',
'item3' => 'value3'
);
Here is the result I want:
$result = array(
'item1' => 'value1',
'item2' => 'value2',
'item3' => 'value3',
'item4' => ''
);
You can do it this way, but I don’t think this is a good solution - I really don’t like to take a simple exit and suppress PHP errors by adding @: s to the code. This pattern will obviously throw errors because 'item4'it is not in $array2, based on this example.
foreach ($keys as $k => $v){
@$array[$v] = $items[$v];
}
, ( ) ?