Pages

08 March, 2024

PHP compare two arrays and output all with zero at different record

I have two arrays:



Array1:

ID: 1
ID: 2
ID: 3
ID: 4
ID: 5




Array2, with num value:

ID: 2, NUM: 200
ID: 4, NUM: 400




I want the output like: (adding zero if no record in array2)

ID: 1, NUM: 0
ID: 2, NUM: 200
ID: 3, NUM: 0
ID: 4, NUM: 400
ID: 5, NUM: 0




I am new to PHP, tried array_diff and array_intersect but not find the clue, could you please let me know how can I do that?



Thanks.

No comments:

Post a Comment

Thanks