title: Create a new array based of of day index and the day
body: <p>I'm having trouble trying to create a new array based on day_index and checking to see if that day exists or not in an array of objects.</p>
  <p><code>$working_hours_arr</code> contains the <em>working</em> days; I'd like to create a new array based on this where if the day_index doesn't exist in this array, to add that day and the state working to false (and the day_index), if it does exist, add <code>working</code> with <code>true</code> and the day index.</p>
  <p>How can I do this?</p>
  <p>The current output is that none matches.</p>
  <pre><code>$working_hours_arr = '[{&quot;day_index&quot;:&quot;2&quot;,&quot;start_time&quot;:&quot;10:00:00&quot;,&quot;end_time&quot;:&quot;19:00:00&quot;,&quot;break&quot;:[]},{&quot;day_index&quot;:&quot;3&quot;,&quot;start_time&quot;:&quot;11:00:00&quot;,&quot;end_time&quot;:&quot;20:00:00&quot;,&quot;break&quot;:[]},{&quot;day_index&quot;:&quot;4&quot;,&quot;start_time&quot;:&quot;10:00:00&quot;,&quot;end_time&quot;:&quot;19:00:00&quot;,&quot;break&quot;:[]},{&quot;day_index&quot;:&quot;5&quot;,&quot;start_time&quot;:&quot;11:00:00&quot;,&quot;end_time&quot;:&quot;20:00:00&quot;,&quot;break&quot;:[]}]';
  
  $days = [
      'Sunday' =&gt; 1,
      'Monday' =&gt; 2,
      'Tuesday' =&gt; 3,
      'Wednesday' =&gt; 4,
      'Thursday' =&gt; 5,
      'Friday' =&gt; 6,
      'Saturday' =&gt; 7,
  ];
  
  $schedule = [];
  foreach ($days as $day =&gt; $index) {
      foreach(json_decode($working_hours_arr) as $obj) {
          $dayIndex = (int)$obj-&gt;day_index;
          if ($index == $dayIndex) {
              $schedule[$day] = ['day_index' =&gt; $index];
              $schedule[$day] = ['working' =&gt; true]; 
          } else {
              $schedule[$day] = ['day_index' =&gt; $index];
              $schedule[$day] = ['working' =&gt; false]; 
          }
      }
  }
  
  var_dump($schedule); 
  </code></pre>