How can I use Array1 and Array2 to get the Wanted Result?
Array1
array(
(int) 0 => '37',
(int) 1 => '38'
)
Array2
array(
(int) 0 => array(
'ParentKey' => array(
'ChildKey1' => '1',
'ChildKey2' => '2'
)
),
(int) 1 => array(
'ParentKey' => array(
'ChildKey1' => '1',
'ChildKey2' => '1'
)
)
)
Wanted Result
array(
(int) 0 => array(
'ParentKey' => array(
'Array1Key' => 37,
'ChildKey1' => '1',
'ChildKey2' => '2'
)
),
(int) 1 => array(
'ParentKey' => array(
'Array1Key' => 37,
'ChildKey1' => '1',
'ChildKey2' => '1'
)
)
(int) 2 => array(
'ParentKey' => array(
'Array1Key' => 38,
'ChildKey1' => '1',
'ChildKey2' => '2'
)
),
(int) 3 => array(
'ParentKey' => array(
'Array1Key' => 38,
'ChildKey1' => '1',
'ChildKey2' => '1'
)
)
)
I have tried several things but this got me the closest...
PHP
$data = array();
foreach($Array1 as $id)
{
foreach($Array2 as $Array1Result)
{
$data[]['ParentKey'] = array(
'Array1Key' => $id,
$Array1Result['ParentKey']
);
}
}
Result
array(
(int) 0 => array(
'ParentKey' => array(
'Array1Key' => '37',
(int) 0 => array(
'ChildKey1' => '1',
'ChildKey2' => '2'
)
)
),
(int) 1 => array(
'ParentKey' => array(
'Array1Key' => '37',
(int) 0 => array(
'ChildKey1' => '1',
'ChildKey2' => '1'
)
)
),
(int) 2 => array(
'ParentKey' => array(
'Array1Key' => '38',
(int) 0 => array(
'ChildKey1' => '1',
'ChildKey2' => '2'
)
)
),
(int) 3 => array(
'ParentKey' => array(
'Array1Key' => '38',
(int) 0 => array(
'ChildKey1' => '1',
'ChildKey2' => '1'
)
)
)
)
array('Array1Key' => $id, $Array1Result['ParentKey'])witharray_merge(array('Array1Key' => $id), $Array1Result['ParentKey'])array()after$data[]['ParentKey'] =