title: How to convert array to a json object?
body: <p>I am trying to push values in an array and it comes like</p>
  
  <pre><code>[{"Monday":"11:30"},{"Monday":"12:00"},{"Monday":"23:00"},{"Tuesday":"11:30"},{"Tuesday":"12:00"},{"Tuesday":"23:00"}]
  </code></pre>
  
  <p>But I want it to be an object like</p>
  
  <pre><code>
  {
  
  "Monday" : [ "11:30", "12:00", "23:00"]
  
  "Tuesday" : ["11:30","12:00","23:00"]
  
  }
  </code></pre>
  
  <p>Here is my code snippet</p>
  
  <pre class="lang-php prettyprint-override"><code>$timings = DoctorTimings::where('doctor_id', '=', $input['doctor_id'])-&gt;get();
  $doctor_timings = [];
  
  foreach($timings as $timing) {
      $day_id = $timing-&gt;day_id;
      $time_slot_id = $timing-&gt;time_slot_id;
      $day_id =  Days::where('id', '=', $day_id)-&gt;first()-&gt;day;
      $time_id = DB::table('time_slot')-&gt;where('id', '=', $time_slot_id)-&gt;select('time')-&gt;first()-&gt;time;  
      array_push($doctor_timings, array($day_id =&gt; $time_id));
  }
  
  $doctorTimings = json_encode($doctor_timings);
  
  echo $doctorTimings;
  </code></pre>