I have two arrays $array
and $array2
. I need to merge them on behalf of common key value i.e. entry_id.
Well I need to merge them is such a way that if the entry_id of array 1 matches with the entry_id of array2, it merges. If the entry_id doesn't match that array remains as it but it should be entered in the merged array. I have tried but i didn't get the desired results. If it is possible to do this without function?
Thanks in Advance.
Here is my code
<?php
$array = array(
array(
'title' => 'mytitleeee',
'entry_id' => 1000
),
array(
'title' => 'myt',
'entry_id' => 1001
),
array(
'title' => 'mytRRRR',
'entry_id' => 1003
),
array(
'title' => 'RUKES',
'entry_id' => 1004
)
);
$array2 = array(
array(
'author_id' => 'desc1',
'entry_id' => 1000
),
array(
'author_id' => 'desc2',
'entry_id' => 1001
),
array(
'author_id' => 'desc3',
'DAY' => 'MON',
'entry_id' => 1003
),
array(
'author_id' => 'desc7',
'DAY' => 'TUE',
'entry_id' => 1012
)
);
$x = array();
foreach($array as $value => $ans){
}
foreach($array2 as $value1 => $ans1){
}
if($ans1['entry_id']!= $ans['entry_id']){
$x = ($ans1);
echo"<pre>";
print_r($x);
}