I have multidimensional array looks like that:
Array3: [
0 => array:2 [
model_id => 1
price => 2000
]
1 => array:2 [
model_id => 2
price => 3000
]
2 => array:2 [
model_id => 1
price => 1500
]
]
Now I need to check if value of model_id occurs more than once, if so I need to take this one where price value is lower. In this example I have model_id = 1 twice so I should take second one because have lowest price.
How can I do this? I have tried this methods:
how can I get the duplicate multidimensional array in php
PHP: Check for duplicate values in a multidimensional array
Finding Duplicate Values in Multi-dimensional Array
But I still can't deal with the problem. Resulting array should look like that:
Array2: [
0 => array:2 [
model_id => 2
price => 3000
]
1 => array:2 [
model_id => 1
price => 1500
]
]