来自exec输出的2D数组

时间:2015-07-07 10:29:28

标签: php arrays multidimensional-array

我有代码

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

它给了我一个很好的数组输出

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 

我现在希望将其作为2D数组,以便输出将是我需要的

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

我该怎么做?

当前输出vardump

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 个答案:

答案 0 :(得分:1)

这应该适合你:

只需将array_chunk()数组放入6个已完成的块中:

$chunked = array_chunk($retval, 6);
print_r($chunked);