[英]Laravel Blade is displaying incorrect values for select dropdown
I'm using Laravel 5.4 and I'm creating a form in Blade and one of the <select>
is of all the months. 我正在使用Laravel 5.4,并且正在Blade中创建一个表单,而
<select>
就是所有月份的表单。
@php (
$months = [
'1'=>'01 - January',
'2'=>'02 - February',
'3'=>'03 - March',
'4'=>'04 - April',
'5'=>'05 - May',
'6'=>'06 - June',
'7'=>'07 - July',
'8'=>'08 - August',
'9'=>'09 - September',
'10'=>'10 - October',
'11'=>'11 - November',
'12'=>'12 - December',
]
)
{{Form::select('card_month', array_merge(['' => 'Select Month'], $months),null,['id' => 'exp_month'])}}
When I use Inspect Element to look at the dropdown I see this 当我使用Inspect Element查看下拉菜单时,我看到了
The keys in the $months array don't match the values in Inspect Element. $ months数组中的键与Inspect Element中的值不匹配。
The values start off at 0 instead of 1. 值从0而不是1开始。
BUT If I add a space in front of the keys, then the numbers display correctly under Inspect Element. 但是,如果在按键前面添加空格,则数字会在“检查元素”下正确显示。
' 1'=>'01 - January',
' 2'=>'02 - February',
' 3'=>'03 - March',
' 4'=>'04 - April',
' 5'=>'05 - May',
' 6'=>'06 - June',
' 7'=>'07 - July',
' 8'=>'08 - August',
' 9'=>'09 - September',
' 10'=>'10 - October',
' 11'=>'11 - November',
' 12'=>'12 - December',
Why is this happening and how do I fix it? 为什么会发生这种情况,我该如何解决?
This is not Laravel fault, this is how array_merge function behaves: 这不是Laravel错误,这是array_merge函数的行为:
Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
使用数字键的输入数组中的值将使用从结果数组中的零开始的递增键重新编号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.