如何将结果分成3列

I have a set of results (e.g. [1,2,3,4,5,6,7,8,9,10,11]).

Which I want to be displayed as 1 row with 3 columns

1|5|9
2|6|10
3|7|11
4|8|

What I get is 1 row with 4 columns

1|4|7
2|5|8
3|6|9

10|
11|

Until I add a 12th object then I get 1 row with 3 columns

1|5|9
2|6|10
3|7|11
4|8|12

My code in blade template

<!-- partials/tables/table_list.blade.php -->

@section('tables')
<?php $chunkSize = floor(count($tables) / 3); ?>
<section id="tables-overview">
    <div class="row">
        @foreach ($tables->chunk($chunkSize , 1) as $chunk)
        <div class="col-md-4">
            @include('partials.tables.table_chunk')
        </div>
        @endforeach
    </div>
</section>
@endsection

<!-- partials/tables/table_chunk.blade.php -->

<table class="table table-responsive">
<thead>
    <tr>
        <th class="text-center">@lang('table.identifier')</th>
        <th class="text-center">@lang('table.property')</th>
        <th class="text-center">
            @permission('manage-tables')
                <a href="{{ route('CreateTable') }}">@lang('action.create')</a>
            @endpermission
        </th>
    </tr>
</thead>
<tbody>
    @foreach ($chunk as $table)
    <tr>
        <td class="text-center">{{ $table->getId() }}</td>
        <td class="text-center">{{ $table->getProperty() }}</td>
        <td class="text-center">
            @permission('manage-tables')
                <a class="btn btn-primary" href="{{ route('UpdateTable', ['id' => $table->getId()]) }}">@lang('action.update')</a>
            @endpermission
        </td>
    </tr>
    @endforeach

</tbody>
</table>

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 here but I find this to be 'odd'. When reading a list you read from top to bottom first and then left to right.

UPDATE I also tried using ceil() as suggested by Huzaib Shafi. But then I get

4 objects (funny looking)
1|3|
2|4|

5 objects (better looking)
1|3|5
2|4

which is also not 100% what I wanted but is pretty close to it. I will try the suggestion of Homam Alhaytham next.

When you floor the division result, you get the lower number.

Explanation: floor(11/3) = 3. Hence your result gets chunked 3 at a time (resulting in; [3,3,3,2]), however we need [4,4,3].

So you need to ceil it. Giving you 4, thus the result.

<?php $chunkSize = ceil(count($tables) / 3); ?>

Use array_chunk.

Assuming you have the following array:

[
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
];

In your .blade.php file you can do something like this:

@section('tables')
<section id="tables-overview">
    <div class="row">
        @foreach (array_chunk($tables, 3) as  $chunk)
        <div class="col-md-4">
            @foreach($chunk as $key => $value)
            //@include('partials.tables.table_chunk')
            // No need to include anything here
            // just write your table instead of including
            @endforeach
        </div>
        @endforeach
    </div>
</section>
@endsection

after you get $items by fetch database data and use loop example

$c=0;
echo '<div class="row">';
while(bla bla bla ..){
// counter
$c++;
echo '<div class="col-md-4">
some thing 
        </div>';
if(fmod($c,3)==0){
echo '</div><div class="row">';
}
}

echo '</div>';

here i used fmod($c,3) 3 number off your columns and fmod return 0 if $c is 6,9,12,15,18.....