title: How to chunk results into 3 columns
body: <p>I have a set of results (e.g. [1,2,3,4,5,6,7,8,9,10,11]).</p>
  
  <p>Which I want to be displayed as 1 row with 3 columns</p>
  
  <pre><code>1|5|9
  2|6|10
  3|7|11
  4|8|
  </code></pre>
  
  <p>What I get is 1 row with 4 columns</p>
  
  <pre><code>1|4|7
  2|5|8
  3|6|9
  
  10|
  11|
  </code></pre>
  
  <p>Until I add a 12th object then I get 1 row with 3 columns</p>
  
  <pre><code>1|5|9
  2|6|10
  3|7|11
  4|8|12
  </code></pre>
  
  <p>My code in blade template</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!-- partials/tables/table_list.blade.php --&gt;
  
  @section('tables')
  &lt;?php $chunkSize = floor(count($tables) / 3); ?&gt;
  &lt;section id="tables-overview"&gt;
      &lt;div class="row"&gt;
          @foreach ($tables-&gt;chunk($chunkSize , 1) as $chunk)
          &lt;div class="col-md-4"&gt;
              @include('partials.tables.table_chunk')
          &lt;/div&gt;
          @endforeach
      &lt;/div&gt;
  &lt;/section&gt;
  @endsection
  
  &lt;!-- partials/tables/table_chunk.blade.php --&gt;
  
  &lt;table class="table table-responsive"&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th class="text-center"&gt;@lang('table.identifier')&lt;/th&gt;
          &lt;th class="text-center"&gt;@lang('table.property')&lt;/th&gt;
          &lt;th class="text-center"&gt;
              @permission('manage-tables')
                  &lt;a href="{{ route('CreateTable') }}"&gt;@lang('action.create')&lt;/a&gt;
              @endpermission
          &lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      @foreach ($chunk as $table)
      &lt;tr&gt;
          &lt;td class="text-center"&gt;{{ $table-&gt;getId() }}&lt;/td&gt;
          &lt;td class="text-center"&gt;{{ $table-&gt;getProperty() }}&lt;/td&gt;
          &lt;td class="text-center"&gt;
              @permission('manage-tables')
                  &lt;a class="btn btn-primary" href="{{ route('UpdateTable', ['id' =&gt; $table-&gt;getId()]) }}"&gt;@lang('action.update')&lt;/a&gt;
              @endpermission
          &lt;/td&gt;
      &lt;/tr&gt;
      @endforeach
  
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When the number of $tables can be divided by 3 (number of columns I want) I get 3 chunks. If not I get 3 chunks + the remaining 1 or 2 objects which both get put in a 4th column. I can place them horizontally as done <a href="https://stackoverflow.com/questions/38066878/split-results-into-5-columns/38066912#38066912">here</a> but I find this to be 'odd'. When reading a list you read from top to bottom first and then left to right.</p>
  
  <p><strong>UPDATE</strong>
  I also tried using ceil() as suggested by <em>Huzaib Shafi</em>. But then I get</p>
  
  <pre><code>4 objects (funny looking)
  1|3|
  2|4|
  
  5 objects (better looking)
  1|3|5
  2|4
  </code></pre>
  
  <p>which is also not 100% what I wanted but is pretty close to it. I will try the suggestion of <em>Homam Alhaytham</em> next.</p>