drrog9853 2015-07-07 10:29
浏览 49
已采纳

来自exec输出的2D数组

I have the code

foreach ($retval as $line) {  // process array line by line
    echo "$line 
";
}

and it gives me a nice array with output of

FieldType: Text 
FieldName: Job title 
FieldFlags: 0 
FieldValue: ICT Manager 
FieldJustification: Left
--- 
FieldType: Text 
FieldName: Hours Per Week 
FieldFlags: 0 
FieldValue: 35 
FieldJustification: Left 
--- 
FieldType: Text 
FieldName: Reporting To 
FieldFlags: 0 
FieldValue: Jerry Woolner 
FieldJustification: Left 
--- 
FieldType: Text 
FieldName: Main Duties/Repsonsibilities 
FieldFlags: 4096 
FieldValue: dfhg fdhg fgh fghfgh fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh 
FieldJustification: Left 

I now want to get this as a 2D array so that the output will be what i need which is

Array [0]
      array[0] = FieldType: Text 
      array[1] = FieldName: Job title 
      array[2] = FieldFlags: 0 
      array[3] = FieldValue: ICT Manager 
      array[4] = FieldJustification: Left 
      array[5] = --- 

Array [1]
      array[0] = FieldType: Text 
      array[1] = FieldName: Hours Per Week 
      array[2] = FieldFlags: 0 
      array[3] = FieldValue: 35 
      array[4] = FieldJustification: Left 
      array[5] = --- 

etc etc

how can i do this ?

current output vardump is

array(25) { [0]=> array(0) { } [1]=> string(3) "---" [2]=> string(15) "FieldType: Text" [3]=> string(20) "FieldName: Job title" [4]=> string(13) "FieldFlags: 0" [5]=> string(23) "FieldValue: ICT Manager" [6]=> string(24) "FieldJustification: Left" [7]=> string(3) "---" [8]=> string(15) "FieldType: Text" [9]=> string(25) "FieldName: Hours Per Week" [10]=> string(13) "FieldFlags: 0" [11]=> string(14) "FieldValue: 35" [12]=> string(24) "FieldJustification: Left" [13]=> string(3) "---" [14]=> string(15) "FieldType: Text" [15]=> string(23) "FieldName: Reporting To" [16]=> string(13) "FieldFlags: 0" [17]=> string(25) "FieldValue: Jerry Woolner" [18]=> string(24) "FieldJustification: Left" [19]=> string(3) "---" [20]=> string(15) "FieldType: Text" [21]=> string(39) "FieldName: Main Duties/Repsonsibilities" [22]=> string(16) "FieldFlags: 4096" [23]=> string(686) "FieldValue: dfhg fdhg fgh fghfgh fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh h fgh dfghdfghfdgh dfgh dfghfdgh gfhdfgh" [24]=> string(24) "FieldJustification: Left" }
  • 写回答

1条回答 默认 最新

  • donglu9445 2015-07-07 10:38
    关注

    This should work for you:

    Just array_chunk() your array into chunks of 6 an done:

    $chunked = array_chunk($retval, 6);
    print_r($chunked);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在