download12749 2012-07-19 21:26
浏览 32
已采纳

将2d数组转换为1d PHP

I have an array (sample below) containing 3 arrays with very similar content. I was wondering if there was an easy way to put everything into one array, rather than 3 separate ones. Everything I try seems to just overwrite the data and I'm left with the info from the 3rd array only.

array
  0 => 
    array
      'america' => int 19
      'music' => int 6
      'states' => int 5
      'bank' => int 5
  1 => 
    array
      'america' => int 19
      'home' => int 3
      'society' => int 2
      'writers' => int 2
   2 => 
    array
      'america' => int 19
      'lutheran' => int 4
      'church' => int 4
      'national' => int 4
      'cruises' => int 3

Ideally the end result will look like this:

array
          'america' => int 19
          'music' => int 6
          'states' => int 5
          'bank' => int 5
          'america' => int 19
          'home' => int 3
          'society' => int 2
          'writers' => int 2
          'america' => int 19
          'lutheran' => int 4
          'church' => int 4
          'national' => int 4
          'cruises' => int 3

Any solutions? thanks

  • 写回答

4条回答 默认 最新

  • douweng3564 2012-07-19 21:28
    关注

    You won't be able to have an associative array with the same key values (i.e. 3 keys of "America", etc.). When you try to set those keys in the array, you will simply overwrite the previous value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿