php - 合并数组的两个字段值

标签 php arrays

我有一个数组,我想将它的两个字段值合并到一个字段中。 需要 link = 链接 + 脚注

  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
            )
    )

需要输出

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
)

这是我的做法

    $result = array();
foreach($item as $val){
    foreach($item['footnote'] as $val1){
        $result['link'] = $val1;
    }
}
pr($result);

最佳答案

$array['link'] = array_merge(array($array['link']), $array['footnote']);
unset($array['footnote']);
print_r($array);

关于php - 合并数组的两个字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18042679/

相关文章:

JavaScript:使用无效索引初始化对象数组

php - 避开 laravel 的公用文件夹,直接在 web 服务器中打开根目录

php - 当通过 PHP 路由时,CSS 将无法通过 Heroku 工作

php - 是否可以从 PHP 的包含路径中排除 '.'(即当前目录)?

php - 在php中将长度超过16位的int转换为字符串

arrays - 混淆错误 : Optionality of map's variable changes it from single object to array

ruby - 复制 Ruby 字符串数组

javascript - 包含数组的对象 - 是否有更简单的方法来编写这种常见模式

php - 如何强制 Doctrine 更新数组类型字段?

php - 将 php 变量传递到 JavaScript 时出现问题