I have a PHP multidimensional associative array with the following structure:
Fields: TYPE - COLOUR - SIZE - PRICE
[0] - rose, var2, var3, price
[1] - rose, var2, var3, price
[2] - daffodil, var2, var3, price
[3] - tulip, var2, var3, price
[4] - rose, var2, var3, price
[5] - tulip, var2, var3, price
[6] - daffodil, var2, var3, price
I want to go through this array and for each type I want to choose the one with the lowest price and delete all other rows of that type. The keys don’t have to be preserved.
In the end I want an array with only one row for each type.
Getting confused at how to do this so any pointers gratefully received.
EDIT:
Sorry probably have made my array clear enough, here’s another snippet of it:
Fields: TYPE - COLOUR - SIZE - PRICE
[0] - type=>rose, colour=>var2, size=>var3, price=>£price
[1] - type=>rose, colour=>var2, size=>var3, price=>£price
[2] - type=>daffodil, colour=>var2, size=>var3, price=>£price
[3] - type=>tulip, colour=>var2, size=>var3, price=>£price
[4] - type=>rose, colour=>var2, size=>var3, price=>£price
[5] - type=>tulip, colour=>var2, size=>var3, price=>£price
[6] - type=>daffodil, colour=>var2, size=>var3, price=>£price
Edited version of Mikhail’s solution to return what OP asked for.