A
Anonymous
Guest
Good to everyone.
I need to iterate over the array according to a certain condition. I access the DB, and I get a response with an array of data:
How can I get such a result, how to group by the "equipment_id" field.
What should I read and what examples should I pay attention to?
I need to iterate over the array according to a certain condition. I access the DB, and I get a response with an array of data:
Code:
[
{
"id": 222,
"equipment_id": 141490,
"datetime": "2021-02-07 23:08:07",
"distance": 5.48,
"speed": 0.02
},
{
"id": 223,
"equipment_id": 141490,
"datetime": "2021-02-07 23:10:08",
"distance": 6.09,
"speed": 0.02
},
{
"id": 224,
"equipment_id": 141490,
"datetime": "2021-02-07 23:11:01",
"distance": 6.36,
"speed": 0.02
},
{
"id": 418,
"equipment_id": 141491,
"datetime": "2021-02-07 22:05:38",
"distance": 341.65,
"speed": 0
},
{
"id": 419,
"equipment_id": 141491,
"datetime": "2021-02-07 22:06:03",
"distance": 341.65,
"speed": 0
},
{
"id": 1065,
"equipment_id": 141491,
"datetime": "2021-02-08 04:55:46",
"distance": 172.12,
"speed": 1.24
},
{
"id": 1066,
"equipment_id": 141491,
"datetime": "2021-02-08 04:56:22",
"distance": 184.51,
"speed": 0.72
},
]
How can I get such a result, how to group by the "equipment_id" field.
What should I read and what examples should I pay attention to?
Code:
{
"equipment_id": 141490,
"speed": {
"datetime": "2021-02-07 23:08:07",
"value": 0.02,
"distance": 5.48,
},
{
"datetime": "2021-02-07 23:10:08",
"value": 0.02,
"distance": 6.09,
},
{
"datetime": "2021-02-07 23:11:01",
"value": 0.02,
"distance": 6.36,
},
},
{
"equipment_id": 141491,
"speed": {
"datetime": "2021-02-07 22:06:03",
"value": 0,
"distance": 341.65,
},
{
"datetime": "2021-02-08 04:55:46",
"value": 0.02,
"distance": 172.12,
},
{
"datetime": "2021-02-08 04:56:22",
"value": 0.72,
"distance": 184.51,
},
},