转换为一个数组删除php中的重复值
每个数组都包含具有相同学生 ID 的不同类型的考试。 数组值推送第一个数组接收值。
数组1
Array (
[0] => Array ( [student_id] => 1190101 [stname] => Student 1 [remarks] => [totals] => 21 )
[1] => Array ( [student_id] => 1190102 [stname] => Student 2 [remarks] => 1 [totals] => 6 )
[2] => Array ( [student_id] => 1190103 [stname] => Student 3 [remarks] =>
[totals] => 11 )
[3] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => 1 [totals] => 6 )
[4] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => 1 [totals] => 6 )
[5] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => 1 [totals] => 6 )
[6] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => 1 [totals] => 6 )
[7] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => 1 [totals] => 6 )
[8] => Array ( [student_id] => 1190109 [stname] => Student 9 [remarks] => 1 [totals] => 6 )
[9] => Array ( [student_id] => 1190110 [stname] => Student 10 [remarks] => 1 [totals] => 6 ) )
数组2
Array (
[0] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => [totals] => 5 )
[1] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => [totals] => 5 ) )
数组3
Array (
[0] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => [totals] => 5 )
[1] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => [totals] => 5 )
[2] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => [totals] => 5 )
)
需要单个多维数组,例如
Array (
[0] => Array ( [student_id] => 1190101 [stname] => Student 1 [remarks] => 1 [totals] => 21 )
[1] => Array ( [student_id] => 1190102 [stname] => Student 2 [remarks] => 1 [totals] => 6 )
[2] => Array ( [student_id] => 1190103 [stname] => Student 3 [remarks] => [totals] => 11 )
[3] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => 1 [totals] => 6*[totals] => 5* )
[4] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => 1 [totals] =>4 [totals] => 5 )
[5] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => 1 [totals] => 6[totals] => 5 )
[6] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => 1 [totals] => 6 [totals] => 5 )
[7] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => 1 [totals] => 6 )
[8] => Array ( [student_id] => 1190109 [stname] => Student 9 [remarks] => 1 [totals] => 6 [totals] => 5 )
[9] => Array ( [student_id] => 1190110 [stname] => Student 10 [remarks] => 1 [totals] => 6 )
)
Each array hold different type of exam with same student Id.second
array value push first array receptive value .
Array 1
Array (
[0] => Array ( [student_id] => 1190101 [stname] => Student 1 [remarks] => [totals] => 21 )
[1] => Array ( [student_id] => 1190102 [stname] => Student 2 [remarks] => 1 [totals] => 6 )
[2] => Array ( [student_id] => 1190103 [stname] => Student 3 [remarks] =>
[totals] => 11 )
[3] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => 1 [totals] => 6 )
[4] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => 1 [totals] => 6 )
[5] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => 1 [totals] => 6 )
[6] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => 1 [totals] => 6 )
[7] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => 1 [totals] => 6 )
[8] => Array ( [student_id] => 1190109 [stname] => Student 9 [remarks] => 1 [totals] => 6 )
[9] => Array ( [student_id] => 1190110 [stname] => Student 10 [remarks] => 1 [totals] => 6 ) )
array 2
Array (
[0] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => [totals] => 5 )
[1] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => [totals] => 5 ) )
array 3
Array (
[0] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => [totals] => 5 )
[1] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => [totals] => 5 )
[2] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => [totals] => 5 )
)
Need Single multidimensional array Like
Array (
[0] => Array ( [student_id] => 1190101 [stname] => Student 1 [remarks] => 1 [totals] => 21 )
[1] => Array ( [student_id] => 1190102 [stname] => Student 2 [remarks] => 1 [totals] => 6 )
[2] => Array ( [student_id] => 1190103 [stname] => Student 3 [remarks] => [totals] => 11 )
[3] => Array ( [student_id] => 1190104 [stname] => Student 4 [remarks] => 1 [totals] => 6*[totals] => 5* )
[4] => Array ( [student_id] => 1190105 [stname] => Student 5 [remarks] => 1 [totals] =>4 [totals] => 5 )
[5] => Array ( [student_id] => 1190106 [stname] => Student 6 [remarks] => 1 [totals] => 6[totals] => 5 )
[6] => Array ( [student_id] => 1190107 [stname] => Student 7 [remarks] => 1 [totals] => 6 [totals] => 5 )
[7] => Array ( [student_id] => 1190108 [stname] => Student 8 [remarks] => 1 [totals] => 6 )
[8] => Array ( [student_id] => 1190109 [stname] => Student 9 [remarks] => 1 [totals] => 6 [totals] => 5 )
[9] => Array ( [student_id] => 1190110 [stname] => Student 10 [remarks] => 1 [totals] => 6 )
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以迭代每个数组并将所有数据放入一个新数组中,使用学生 ID 作为键:
因此每次它找到已添加的学生时,它都会再次添加信息。如果 array2 有关于 123 号学生的一条数据,而 array1 没有,则会通过 key 将其添加到新数组中的 123 号学生的数组中。
这假设每个学生 ID 都是正确的,并且每个 ID 中只有一个学生,每个学生只有一个 ID,并且其他信息(如 stname 或备注)在不同的数组中没有冲突。
You could iterate through each array and put all the data into a new array, using student ID as the key:
So each time it finds a student that was already added, it will add the information again. If array2 has a piece of data on student #123 that array1 didn't have, it will be added to student #123's array in the new array by the key.
This assumes that each student ID is correct, and there is only one student per ID and one ID per student, and that none of the other info (like stname or remarks) are conflicting in different arrays.