I have two arrays:
$graph1 = Array (
[0] => Array ( [0] => 202101 [1] => 2 )
[1] => Array ( [0] => 202102 [1] => 3 )
[2] => Array ( [0] => 202103 [1] => 5 )
[3] => Array ( [0] => 202104 [1] => 2 )
[4] => Array ( [0] => 202105 [1] => 3 )
[5] => Array ( [0] => 202106 [1] => 4 )
[6] => Array ( [0] => 202107 [1] => 14 ) )
$graph2 = Array (
[0] => Array ( [0] => 202105 [1] => 3 )
[1] => Array ( [0] => 202107 [1] => 1 )
[2] => Array ( [0] => 202108 [1] => 6 )
)
and want to create a third array with an extra value where value[0] matches, and an extra row and extra value if there is no matching value[0]
I have tried array_merge and array_push but my understanding of arrays is not up to the task The output I want is like this:
$graph3 = Array (
[0] => Array ( [0] => 202101 [1] => 2 [2] => 0 )
[1] => Array ( [0] => 202102 [1] => 3 [2] => 0 )
[2] => Array ( [0] => 202103 [1] => 5 [2] => 0 )
[3] => Array ( [0] => 202104 [1] => 2 [2] => 0 )
[4] => Array ( [0] => 202105 [1] => 3 [2] => 3 )
[5] => Array ( [0] => 202106 [1] => 4 [2] => 0 )
[6] => Array ( [0] => 202107 [1] => 14 [2] => 1 )
[7] => Array ( [0] => 202108 [1] => 0 [2] => 6 ) )
Answers and explanation would be great - thank you