vendredi 6 mai 2016

How to change index position in array push

How to change the index position in array push on json Below is my output:

"MINIMUM": [
    {
      "HCB-6": {
        "min": "3.6"
      },
      "HCB-4": {
        "min": "8.8"
      }
]

Using this code:

$driver_id=$res->driver_id;
$get_distance=str_replace(',','.',$dist);
$distance[$req_latpl] = array();
$distance[$driver_id] = array();
array_push($distance[$req_latpl], $driver_id);
$drivers[$req_latpl]['min'] = min($distance[$req_latpl]); 

How can i change the code to achieve the below output:

"MINIMUM": [
    {
      "min": {
        "distance": "3.6",
         "driver" : "HCB-4"

      },
     {
        "distance": "8.8",
         "driver" : "HCB-4"

      }
]

thanks in advance..!!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WO01Vy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire