Here are my two arrays:
$array1 =( [0] => Array ( [row_id] => 237 [comment] => 'hello0' )
[1] => Array ( [row_id] => 5 [comment] => 'hello1' )
[2] => Array ( [row_id] => 6 [comment] => 'hello2' ) );
$array2= ( [0] => Array ( [row_id] => 5 [vote] => 1 )
[1] => Array ( [row_id] => 7 [vote] => 1 )
[2] => Array ( [row_id] => 237 [vote] => 0 ) );
I’d like to match $array1 and $array2 on [row_id] and add $array2‘s
[vote] key/value pairs to $array1 where $array1[row_id]=$array2[row_id]
This is how I’d like the output to be:
$array1 =( [0] => Array ( [row_id] => 237 [comment] => 'hello0' [vote] => 0 )
[1] => Array ( [row_id] => 5 [comment] => 'hello1' [vote] => 1 )
[2] => Array ( [row_id] => 6 [comment] => 'hello2' [vote] => 1 ) );
I’m sure there are many ways to do this, so thoughts on the fastest computationally would also be appreciated!
1 Answer