This is not a duplicate of the following questions :
I need to merge items in a PHP array, here is an example where I need to merge items with the same UID:
0 =>
array (size=10)
'id' => '958'
'uid' => '385'
'text' => '2021-10-23 08:32:35'
1 =>
array (size=10)
'id' => '956'
'uid' => '385'
'text' => '2021-10-23 08:31:51'
2 =>
array (size=10)
'id' => '957'
'uid' => '386'
'timestamp' => '2021-10-23 08:32:12'
3 =>
array (size=10)
'id' => '955'
'uid' => '385'
'timestamp' => '2021-10-23 08:31:38'
Elements 0, 1 and 3 have the same UID, so the expected array after merging elements with same UID is:
0 =>
array (size=10)
'id' => '958'
'uid' => '385'
'text' => '2021-10-23 08:32:35'
1 =>
array (size=10)
'id' => '957'
'uid' => '386'
'timestamp' => '2021-10-23 08:32:12'
I need to keep the item with the smallest key.