合并 2 个数组并将它们放入表中

发布于 2024-10-28 13:50:36 字数 1665 浏览 1 评论 0原文

更新

我是新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白龙吟 2024-11-04 13:50:36

查看php函数array_combinearray_merge

Look at usage of php function array_combine and array_merge

递刀给你 2024-11-04 13:50:36

警告“为 foreach() 提供的参数无效”通常意味着您传递的变量不是数组或对象,或者数组或对象为空。

如果您可以确定数组不为空,则可以使用:


if (!empty($arrayStudents))) {
  foreach($arrayStudents as $keyStudents => $valueStudent) {
    $studentUGentID[$keyStudents] = $valueStudent->field_ugentid_student;
    $studentPreference[$keyStudents] = $valueStudent->field_voorkeur_student;
    $studentLocation[$keyStudents] = $valueStudent->field_locatie_student;
  }
}

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:


if (!empty($arrayStudents))) {
  foreach($arrayStudents as $keyStudents => $valueStudent) {
    $studentUGentID[$keyStudents] = $valueStudent->field_ugentid_student;
    $studentPreference[$keyStudents] = $valueStudent->field_voorkeur_student;
    $studentLocation[$keyStudents] = $valueStudent->field_locatie_student;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文