Good day!
Tell me, please, I can't find (guess) the solution.. How to do the sorting (in PHP 5.6/7) of a multidimensional JSON array by value of a certain key (ascending) and further alphabetically (other key)?
Let me explain. There's such an array:
[{
"id": "26",
"strana": "Thailand",
"otel_nazvanie": "Villa Danica",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "22900"
}, {
"id": "26",
"strana": "Greece",
"otel_nazvanie": "Vila Tufi",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "27700"
}, {
"id": "26",
"strana": "Cyprus",
"otel_nazvanie": "Villa Kralj",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "28800"
}, {
"id": "26",
"strana": "Cyprus",
"otel_nazvanie": "Rooms Rio",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "28750"
}, {
"id": "26",
"strana": "Thailand",
"otel_nazvanie": "Zelena Obala",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "32050"
}, {
... // and so forth, up to 100 pieces.
}]
As it can be sorted (once, I mean at one time), to:
+ Sorted by alphabetical order of the key values
strana;
+ Sorted in ascending order of key values
otel_stoimost;
+ Next, output only the first element of a sorted (according to the parameters above) of the array;
That is, the result should look like this:
[{
"id": "26",
"strana": "Greece",
"otel_nazvanie": "Vila Tufi",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "27700"
}, {
"id": "26",
"strana": "Cyprus",
"otel_nazvanie": "Rooms Rio",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "28750"
}, {
"id": "26",
"strana": "Thailand",
"otel_nazvanie": "Villa Danica",
"otel_kol_vo_zvezd": "3",
"otel_stoimost": "22900"
}, {
... // and so on.
}]
What is needed: to make the filter in the directions of tourism. The final version should go like this (example from data above):
- Greece from 27 700 RUB.
- Cyprus from 28 750 rubles.
- Thailand from 22 900 RUB.
Very hope for your help, he is actually sitting with a square head.. :(
otel_stoimost
from smaller to larger number? - cullen.Douglas commented on July 9th 19 at 11:22