Combine 2 array's and puth these in a table
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; //开发者_如何学Python 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?
Look at usage of php function array_combine and array_merge
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;
}
}
精彩评论