【发布时间】:2011-04-01 07:10:00
【问题描述】:
更新,解决
我有以下 2 个数组(长度相同),我想在表格中显示这些值。问题是他只打印我的第一个数组 ($gPositionStudents) 而不是数组 $gPositionInternships 的值。 目标是将每个学生与不同的实习联系起来,但我知道这两个数组之间没有关系。我正在寻找一个可以移动这两个数组的函数,这样每次我移动学生都有另一个实习机会。
重要的是要知道,我对数组 $gStartPositionInternship 做了一个小修改,我使这个数组的大小与数组 $gStartPositionStudents 的长度相等。使用以下代码:
enter code here// 使 $gStartPositionInternships 中的项目只要数组 $gStartPositionStudents
$gStartPositionInternships = array_pad($internships, $lengthStudentArray, 'null');
我包括了我当前的输出,见图:
enter code here// Make table
$header = array();
$header[] = array('data' => 'Internship');
$header[] = array('data' => 'UGentID');
// this big array will contains all rows
// global variables.
global $gStartPositionStudents;
global $gStartPositionInternships;
$rows = array();
foreach($gStartPositionStudents as $value) {
foreach($gStartPositionInternships as $key=>$value2) {
// each loop will add a row here.
$row = array();
// build the row
$row[] = array('data' => $value[0]['value']);
$row[] = array('data' => $value2);
}
// add the row to the "big row data (contains all rows)
$rows[] = array('data' => $row);
}
$output = theme('table', $header, $rows);
return $output;
$gPositionStudents 的 var_dump
array(148) {
[0]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "804868"
}
}
[1]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "804869"
}
}
[2]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "705169"
}
}
[3]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "805148"
}
}
[4]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "702342"
}
}
[5]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "803176"
}
}
[6]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "706651"
}
}
[7]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "706333"
}
}
[8]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "806026"
}
}
[9]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "702808"
}
}
var_dump of: $gPositionInternships
array(148) {
[0]=>
string(18) "Pcv (campus Aalst)"
[1]=>
string(53) "Mss ( Privaatpraktijk kinesitherapie Walravens Marc )"
[2]=>
string(54) "Mss ( Privaatpraktijk kinesitherapie Peeters Stefaan )"
[3]=>
string(35) "psychiatrie (campus Vercruysselaan)"
[4]=>
string(39) "interne geneeskunde (campus Loofstraat)"
[5]=>
string(40) "interne geneeskunde (campus Kennedylaan)"
[6]=>
string(29) "heelkunde (campus Loofstraat)"
[7]=>
string(30) "heelkunde (campus Kennedylaan)"
[8]=>
string(33) "heelkunde (campus Vercruysselaan)"
[9]=>
string(38) "logopedie (groepspraktijk Logomatopee)"
[10]=>
string(41) "logopedie (Koninklijk Instituut Spermali)"
[11]=>
string(34) "Fysieke activiteit (To Walk Again)"
[12]=>
string(53) "algemene en plastische heelkunde ( AZ AZ Oudenaarde )"
[13]=>
string(38) "dermatologie (campus Maria Middelares)"
[14]=>
string(29) "NKO (campus Maria Middelares)"
[15]=>
string(38) "dermatologie (campus Maria Middelares)"
[16]=>
string(38) "Fysieke activiteit (Beweegkamp Vlabus)"
[17]=>
string(43) "Hoofdverpleegkundige ( UZ UZ Gent Urologie)"
[18]=>
string(66) "Opleidingscoördinator ( Onderwijsinstelling Arteveldehogeschool )"
[19]=>
string(90) "Verpleegkundig Specialist ( UMC Universitair Medisch Centrum Universitair Medisch Centrum)"
[20]=>
string(31) "Mss ( AZ Nikolaas campus Hamme)"
[21]=>
string(74) "Mss ( Privaatpraktijk kinesitherapie Cuigniez Pascale PR Cuigniez Pascale)"
【问题讨论】:
-
您不应该使用相同的 $key 变量。如果您不需要它们,请不要声明它们
-
是的,我知道。但没有解决问题。
-
你在上面的代码中对
$header做了什么??