如何在特定索引值之间显示列名数组

时间:2018-03-01 23:02:32

标签: php arrays laravel

我有以下列名列,我想只显示日列名,所以7 - 13

array:20 [▼
 0 => "id"
 1 => "customer_id"
 2 => "enrolment_id"
 3 => "course_id"
 4 => "delivery_mode"
 5 => "course_cost"
 6 => "location"
 7 => "Monday"
 8 => "Tuesday"
 9 => "Wednesday"
 10 => "Thursday"
 11 => "Friday"
 12 => "Saturday"
 13 => "Sunday"
 14 => "start_time"
 15 => "end_time"
 16 => "start_date"
 17 => "sale_type"
 18 => "created_at"
 19 => "updated_at"
 ]

使用以下命令在控制器中创建数组:

$columns = Schema::getColumnListing('orders');

我使用以下内容将列名称显示为刀片模板视图中我的复选框的标签,但它显示所有列名称而不仅仅是日期:

@foreach($columns as $column)
{{ Form::checkbox($column, 0, null, ['id' => $column,  'class' => 'is-
checkradio is-white']) }}
{{ Form::label($column, $column) }}
@endforeach

2 个答案:

答案 0 :(得分:0)

感谢Jonas

这适用于问题

$days = array_slice($columns, 7, 7); 

答案 1 :(得分:0)

你可以使用laravel helpers(URL Button Telegram)中的 array_where 来完成这项工作,如下所示:

$columns = array_where($columns, function ($value, $key) {
   return ($value >= 7 && $columns <= 13);
});