合并 2 个数组并将它们放入表中
更新
我是新的 drupal 开发人员,我已经检索了我的节点“学生”和“实习生”。这不是问题。从我的节点“学生”中,我检索了一些值:学生姓名、学生名字、学生 ID。我从节点“实习”中检索到:实习名称和实习地点。现在我想将这些不同的数组组合在一个表中。我包含了表的结构:
Name student | First name student | ID student | Name internship | Name location
Jan Smith 123456 University Ghent Downingstreet 10
我的代码:
$studentUGentID = null;
$studentPreference = null; // voorkeur stageplaats van student.
$studentLocation = null; // Location student.
foreach($arrayStudents as $keyStudents => $valueStudent) {
$studentUGentID[$keyStudents] = $valueStudent->field_ugentid_student;
$studentPreference[$keyStudents] = $valueStudent->field_voorkeur_student;
$studentLocation[$keyStudents] = $valueStudent->field_locatie_student;
}
//var_dump($arrayStudents);
// Get required data from local variable $arrayInternships.
$internshipStagedomein = null;
$internshipNaam = null;
$internshipLocatie = null;
foreach($arrayInternships as $keyInternships => $valueInternship) {
$internshipStagedomein[$keyInternships] = $valueInternship->field_stagedomein_revaki;
$internshipNaam[$keyInternships] = $valueInternship->title;
$internshipLocatie[$keyInternships] = $valueInternship->field_locatieview;
}
我使用以下代码来合并和 theme_table():
$header = array('UGentID', '实习'); $output = theme_table($header, array_merge($studentUGentID, $internshipNaam));
但是,我收到以下错误:
警告:提供的参数无效 foreach() 中 C:\xampp\htdocs\testplanningFinal\includes\theme.inc 第 1389 行。
可能是什么原因?
Update
I'm new a drupal developer, I have retrieved my node 'Student' and 'Internships'. that's not the problem. From my node 'Student' I retrieved some values: name student, first name student, ID from student. From the node 'Internships' I have retrieved: name internship and location internship. Now I want to combine these different arrays with each other in a table. I included the structure of the table:
Name student | First name student | ID student | Name internship | Name location
Jan Smith 123456 University Ghent Downingstreet 10
my code:
$studentUGentID = null;
$studentPreference = null; // voorkeur stageplaats van student.
$studentLocation = null; // Location student.
foreach($arrayStudents as $keyStudents => $valueStudent) {
$studentUGentID[$keyStudents] = $valueStudent->field_ugentid_student;
$studentPreference[$keyStudents] = $valueStudent->field_voorkeur_student;
$studentLocation[$keyStudents] = $valueStudent->field_locatie_student;
}
//var_dump($arrayStudents);
// Get required data from local variable $arrayInternships.
$internshipStagedomein = null;
$internshipNaam = null;
$internshipLocatie = null;
foreach($arrayInternships as $keyInternships => $valueInternship) {
$internshipStagedomein[$keyInternships] = $valueInternship->field_stagedomein_revaki;
$internshipNaam[$keyInternships] = $valueInternship->title;
$internshipLocatie[$keyInternships] = $valueInternship->field_locatieview;
}
I'm using the following code to merge and theme_table():$header = array('UGentID', 'Internships');
$output = theme_table($header, array_merge($studentUGentID, $internshipNaam));
But, i'm receiving the following error:
warning: Invalid argument supplied for
foreach() in
C:\xampp\htdocs\testplanningFinal\includes\theme.inc
on line 1389.
What could be the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看php函数array_combine和array_merge
Look at usage of php function array_combine and array_merge
警告“为 foreach() 提供的参数无效”通常意味着您传递的变量不是数组或对象,或者数组或对象为空。
如果您可以确定数组不为空,则可以使用:
The warning "Invalid argument supplied for foreach()" usually means that the variable you passed is not an array or object, or the array or object is empty.
If you can be sure the array is not empty you can use this: