title: Any idea why did a return function (false or true) stops the looping?
body: <p>I spent almost a day fixing a bug in my code. After a while I decided to put the code of lines one by one and found what makes the loop function stop working then I figured out that it's when I put a return value inside my if-else statement. Any idea guys? I really need my code to return true or false for my validation.
  here's the code before:
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> 
    $day = $this-&gt;input-&gt;post('daysched');
     $count = 0; 
      
      foreach ($day as $key =&gt; $value) 
      { 
         
              
             
  
              
  
          $sched_details = array(
         'sys_id' =&gt; $this-&gt;input-&gt;post('sys_id'),
         'time_in' =&gt; $this-&gt;input-&gt;post('time_in'),
         'time_out' =&gt; $this-&gt;input-&gt;post('time_out'),
         'day' =&gt; $value
         );
  
    $check_details = array(
         'sys_id' =&gt; $this-&gt;input-&gt;post('sys_id'),
         'day' =&gt; $value
         );
  
    $this-&gt;db-&gt;where($check_details);
    $q = $this-&gt;db-&gt;get('tbl_worksched');
  
    if($q-&gt;num_rows==0){ 
  
    $s = $this-&gt;db-&gt;insert('tbl_worksched', $sched_details); 
    return true;
  
    }
  
    else{
  
    return false;
    }
  
    $count++; 
           
      } 
      
      return $count; 
    
  
    
    </code></pre>
  </div>
  </div>
  </p>
  
  <p>and after I make my code work(after I remove the return in if-else statements): </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> $day = $this-&gt;input-&gt;post('daysched');
    $count = 0; 
      
      foreach ($day as $key =&gt; $value) 
      { 
         
          $sched_details = array(
         'sys_id' =&gt; $this-&gt;input-&gt;post('sys_id'),
         'time_in' =&gt; $this-&gt;input-&gt;post('time_in'),
         'time_out' =&gt; $this-&gt;input-&gt;post('time_out'),
         'day' =&gt; $value
         );
  
    $check_details = array(
         'sys_id' =&gt; $this-&gt;input-&gt;post('sys_id'),
         'day' =&gt; $value
         );
  
    $this-&gt;db-&gt;where($check_details);
    $q = $this-&gt;db-&gt;get('tbl_worksched');
  
    if($q-&gt;num_rows==0){ 
  
    $s = $this-&gt;db-&gt;insert('tbl_worksched', $sched_details); 
  
    }
  
    else{
  
    }
  
     $count++; 
  
      } 
      
      return $count; 
    
  
    
   
   }</code></pre>
  </div>
  </div>
  </p>