我有2個陣列的長度相同。陣列$gPositionStudents
和陣列$gPositionInternships
。每個學生都被分配到不同的實習,這部分工作。沒有indexOfOutBounds的換檔陣列
現在我想$gPositionStudent
的第一個元素(索引0)引用數組$gPositionInternship
的第二個(索引1)元素。這隱含意味着$gPositionStudents
的最後一個元素指的是$gPositionInternship
的第一個元素。 (我包括了我的解釋圖片)。
我的代碼是:
// Make table
$header = array();
$header[] = array('data' => 'UGentID');
$header[] = array('data' => 'Internships');
// this big array will contains all rows
// global variables.
global $gStartPositionStudents;
global $gStartPositionInternships;
//var_dump($gStartPositionInternships);
$rows = array();
$i = 0;
foreach($gStartPositionStudents as $value) {
foreach($gStartPositionInternships as $value2) {
// each loop will add a row here.
$row = array();
// build the row
$row[] = array('data' => $value[0]['value']);
//if($value[0] != 0 || $value[0] == 0) {
$row[] = array('data' => $gStartPositionInternships[$i]);
}
$i++;
// add the row to the "big row data (contains all rows)
$rows[] = array('data' => $row);
}
$output = theme('table', $header, $rows);
return $output;
現在我想,我可以選擇多少次,我們可以轉移。 1班或2班或更多班。我想要什麼在PHP中存在?
完美,謝謝您的回覆! – user001 2011-04-06 13:58:02