php - Sort the big array according to the value of another array which is inside the big array -


     {  "result": true,               "users": [{                             "id": 11,                        "expected_count": 13,                     "user_id": 1,                        "event_id": 2,                      "user": {                                "id": 1,                          "name": "moiz jamali"                             }              },          {                   "id": 12,                "expected_count": 12,             "user_id": 2,             "event_id": 2,                   "user": {                              "id": 2,                         "name": "juzer samiwala"                    }           }]  } 

above output of big array ('users').

what want sort big array ('users') according name value inside small array ('user') in php.

can please me this?

thank you.

you can use usort strcmp this. this:

$bigarray = ["result" => true, "users" => [     "id" => 11,     "expected_count" => 13,     "user_id" => 1,     "event_id" => 2,     "user" => [         "id" => 1,         "name" => "moiz jamali"     ],     ... other users ]];  usort($bigarray['users'], function ($a, $b) {     return strcmp($a['user']['name'], $b['user']['name']); }); 

Comments

Popular posts from this blog

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -