Reputation: 2781
I have a array and I want to merge its two field value in one field. need link = link + footnote
Array
(
[title] => CBS Blocks Time
[link] => http://techcrunch.com/2013/08/02/cbs-blocks-time-warner-cable-subscribers-from-watching-full-episodes-on-cbs-com/
[pubDate] => Fri, 02 Aug 2013 00:00:00 +0000
[dc_creator] => Ryan Lawler
[dc_language] => en
[dc_format] => text/html
[footnote] => Array
(
[0] => http://www.twcableuntangled.com/2013/08/twc-removes-cbs-programming/
[1] => https://twitter.com/CBS
[2] => https://twitter.com/TWC
[3] => http://CBS.com
[4] => https://twitter.com/TWC
[5] => http://twitter.com/#!/brianstelter/status/363435685249687552
[6] => http://www.techmeme.com/101016/p12#a101016p12
)
)
Need Output
Array
(
[title] => CBS Blocks Time
[link] => Array
(
[0] => http://techcrunch.com/2013/08/02/cbs-blocks-time-warner-cable-subscribers-from-watching-full-episodes-on-cbs-com/
[1] => http://www.twcableuntangled.com/2013/08/twc-removes-cbs-programming/
[2] => https://twitter.com/CBS
[3] => https://twitter.com/TWC
[4] => http://CBS.com
[5] => https://twitter.com/TWC
[6] => http://twitter.com/#!/brianstelter/status/363435685249687552
[7] => http://www.techmeme.com/101016/p12#a101016p12
)
[pubDate] => Fri, 02 Aug 2013 00:00:00 +0000
[dc_creator] => Ryan Lawler
[dc_language] => en
[dc_format] => text/html
)
This is my approach
$result = array();
foreach($item as $val){
foreach($item['footnote'] as $val1){
$result['link'] = $val1;
}
}
pr($result);
Upvotes: 3
Views: 804
Reputation: 39542
It should be as simple as this:
$array['footnote'][] = $array['link'];
$array['link'] = $array['footnote'];
unset($array['footnote']);
Upvotes: 2
Reputation: 7795
$array['link'] = array_merge(array($array['link']), $array['footnote']);
unset($array['footnote']);
print_r($array);
Upvotes: 2
Reputation: 24276
foreach($array as $key=>$value) {
if ($key == 'link') {
$array[$key] = $array['footnote'];
$array[$key][] = $value;
unset($array['footnote']);
continue;
}
}
Upvotes: 1