title: Foreach loop is giving wrong results
body: <p>I have table data with two conditions <code>price_id =2</code> and <code>price_id = 1</code> and data as like below .
  <a href="https://i.stack.imgur.com/XchJx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XchJx.png" alt="enter image description here"></a></p>
  
  <p>So here my condition if <code>weekday_am</code> column value is <code>null</code> or <code>empty</code> or <code>0.00</code> at <code>price_id =2</code> i need to take that value at <code>price_id = 1</code> and the same logic will apply for the columns <code>weekday_pm</code> , <code>weekend_am</code>, <code>weekend_pm</code> . So what i m doing is i have written two queries with two different conditions and checking the values using foreach loop . But its giving wrong results . </p>
  
  <p>Query code :</p>
  
  <pre><code>$ArrayTier = BundlePrice::where('bundle_id',$id)-&gt;where('price_id','=','2')-&gt;get();
               $ArrayDefault = BundlePrice::where('bundle_id',$id)-&gt;where('price_id','=','1')-&gt;get();
               foreach($ArrayTier as $value)
               {  
                  $bundle_id = $value-&gt;bundle_id;
                  $asset_id = $value-&gt;asset_id;
  
                     foreach($ArrayDefault as $v)
                      {
  
                          if(!empty($value-&gt;weekday_am) || ($value-&gt;weekday_am != null))
                          {
                              $weekam =  $value-&gt;weekday_am;
                          }else{
                              $weekam = $v-&gt;weekday_am;
                          }
  
                          if(!empty($value-&gt;weekday_pm) || ($value-&gt;weekday_pm != null))
                          {
                              $weekpm =  $value-&gt;weekday_pm;
                          }else{
                              $weekpm = $v-&gt;weekday_pm;
                          }
  
                          if(!empty($value-&gt;weekend_am) || ($value-&gt;weekend_am != null))
                          {
                              $nonweekam =  $value-&gt;weekend_am;
                          }else{
                              $nonweekam = $v-&gt;weekend_am;
                          }
  
                         if(!empty($value-&gt;weekend_pm) || ($value-&gt;weekend_pm != null))
                          {
                              $nonweekpm =  $value-&gt;weekend_pm;
                          }else{
                              $nonweekpm = $v-&gt;weekend_pm;
                          }
  
  
  
                      }
                  $primaryArray[] = ['asset_id' =&gt; $asset_id,'weekam' =&gt; $weekam,'weekpm' =&gt; $weekpm,'nonweekam' =&gt; $nonweekam,'nonweekpm' =&gt; $nonweekpm];
               } 
  </code></pre>
  
  <p>For the above query i'm getting wrong like the values are not changing its taking only the last row values at <code>price_id =1</code></p>
  
  <p>The result the above code is :</p>
  
  <pre><code>array:3 [▼
    0 =&gt; array:5 [▼
      "asset_id" =&gt; 2
      "weekam" =&gt; 150.0
      "weekpm" =&gt; 320.0
      "nonweekam" =&gt; 160.0
      "nonweekpm" =&gt; 420.0
    ]
    1 =&gt; array:5 [▼
      "asset_id" =&gt; 1
      "weekam" =&gt; 120.0
      "weekpm" =&gt; 180.0
      "nonweekam" =&gt; 220.0
      "nonweekpm" =&gt; 420.0
    ]
    2 =&gt; array:5 [▼
      "asset_id" =&gt; 4
      "weekam" =&gt; 120.0
      "weekpm" =&gt; 320.0
      "nonweekam" =&gt; 220.0
      "nonweekpm" =&gt; 420.0
    ]
  ]
  </code></pre>
  
  <p>If you see the above , same values are repeating for few places . 
  But expecting results should be like below :</p>
  
  <pre><code>array:3 [▼
    0 =&gt; array:5 [▼
      "asset_id" =&gt; 2
      "weekam" =&gt; 150.0
      "weekpm" =&gt; 300.0
      "nonweekam" =&gt; 160.0
      "nonweekpm" =&gt; 400.0
    ]
    1 =&gt; array:5 [▼
      "asset_id" =&gt; 1
      "weekam" =&gt; 110.0
      "weekpm" =&gt; 180.0
      "nonweekam" =&gt; 210.0
      "nonweekpm" =&gt; 410.0
    ]
    2 =&gt; array:5 [▼
      "asset_id" =&gt; 4
      "weekam" =&gt; 120.0
      "weekpm" =&gt; 320.0
      "nonweekam" =&gt; 220.0
      "nonweekpm" =&gt; 420.0
    ]
  ]
  </code></pre>
  
  <p>Can somebody help me to resolve this ? or please suggest me any mysql query that can do this in single query instead of going through foreach loop. Thank you </p>