I have two arrays: 1. each object here is a row retrived from database.
array 1 => object(stdClass)[41] public 'id' => string '1' (length=1) public 'class_id' => string '25' (length=2) public 'section_id' => string '2' (length=1) public 'student_id' => string '1' (length=1) public 'date' => string '2011-11-27' (length=10) public 'attendance' => string 'present' (length=7) 2 => object(stdClass)[41] public 'id' => string '1' (length=1) public 'class_id' => string '25' (length=2) public 'section_id' => string '2' (length=1) public 'student_id' => string '3' (length=1) public 'date' => string '2011-11-27' (length=10) public 'attendance' => string 'present' (length=7)
2. Another array is from my form and this looks like this.
array 0 => array 'class_id' => string '25' (length=2) 'section_id' => string '2' (length=1) 'student_id' => int 1 'date' => string '2011-11-27 00:00:00' (length=19) 'attendance' => string 'present' (length=7) 1 => array 'class_id' => string '25' (length=2) 'section_id' => string '2' (length=1) 'student_id' => int 2 'date' => string '2011-11-27 00:00:00' (length=19) 'attendance' => string 'present' (length=7)
Here what I want to do is:
- compare these two and check if key student_id and date are already on database or not.
- and from second array which is from form data, remove duplicate and insert into data.
The final result should be:
array 0 => array 'class_id' => string '25' (length=2) 'section_id' => string '2' (length=1) 'student_id' => int 2 'date' => string '2011-11-27 00:00:00' (length=19) 'attendance' => string 'present' (length=7)
Try:
$c = [array_merge][1]($a,$b); var_dump([array_unique][1]($c));
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With