我有两个数组,就像 -
Array
(
[0] => Array
(
[student_id] => 2
[attendance_type] => leave
)
[1] => Array
(
[student_id] => 3
[attendance_type] => absent
)
)
和另一个是 -
Array
(
[0] => Array
(
[attendance_id] => 4
[student_id] => 2
)
)
从第一个数组开始,我需要将attendance_type
与student_id
对齐,所以我首先尝试从数组中选择键attendacnce_type
。怎么可能??
答案 0 :(得分:2)
<?php
$arrayFirst = [['student_id' => 2, 'attendance_type' => 'leave'], ['student_id' => 3, 'attendance_type' => 'absent']];
$arraySecond = ['attendance_id' => 4, 'student_id' => 2];
foreach ($arrayFirst as $key => $arrayFst) {
if($arraySecond['student_id'] == $arrayFst['student_id']) {
$firstArrayKeyValue = $key;
$attendance_type = $arrayFst['attendance_type'];
}
}
echo $firstArrayKeyValue."<br>".$attendance_type;
?>