I have merged an 2 multidimensional arrays with the same info but with different keys using array_merge() and i get the output
Array
(
[0] => Array
(
[Ttitle] => lilly
[Price] => 1.75
[Number] => 3
)
[1] => Array
(
[Title] => rose
[Price] => 1.25
[Number] => 15
)
[2] => Array
(
[Title] => daisy
[Price] => 0.75
[Number] => 25
)
[3] => Array
(
[Title] => nettle
[Price] => 2.75
[Number] => 33
)
[4] => Array
(
[Title] => orchid
[Price] => 1.15
[Number] => 7
)
)
As you can see the first key name in the array is Ttitle and the rest is Title. What I want now is to change all Ttitle keys (just the one at the mo) to Title (like all the others).When I the use array_map() function I manage to change all the keys to Title but i also delete all Title values except for the Ttitle key i just changed to Title.
my array_map() code is as folows
if(! empty($notmatchingarray))
{
$completearray = array_merge($notmatchingarray, $datastuff2);
$completearray = array_map(function($complete) {
return array(
'Title' => $complete['Ttitle'],
'Price' => $complete['Price'],
'Number' => $complete['Number'],
);
}, $completearray);
echo "Array which includes each unique enrty from both arrays";
echo "<pre>";
print_r($completearray);
echo "</pre>";
echo "<br/>";
}
the out put of this code is
Array
(
[0] => Array
(
[Title] => lilly
[Price] => 1.75
[Number] => 3
)
[1] => Array
(
[Title] =>
[Price] => 1.25
[Number] => 15
)
[2] => Array
(
[Title] =>
[Price] => 0.75
[Number] => 25
)
[3] => Array
(
[Title] =>
[Price] => 2.75
[Number] => 33
)
[4] => Array
(
[Title] =>
[Price] => 1.15
[Number] => 7
)
)
Am i doing the wrong thing in using this array_map() function? Should i be doing something else other than that?
regards Mike