【问题标题】:how to make select option value same as name in blades如何使选择选项值与刀片中的名称相同
【发布时间】:2021-10-25 08:02:11
【问题描述】:

DateTimeZone::listIdentifiers() 返回时区数组。值为:

[
  0 => "Africa/Abidjan",
  1 => "Africa/Accra",
  2 => "Africa/Addis_Ababa",
  ...
]

当我在blade中写{{ Form::select('timezone', DateTimeZone::listIdentifiers(), $result->timezone]) }} 时,选项值将是0、1、2。我想让选项值等于时区名称

【问题讨论】:

    标签: laravel laravel-blade


    【解决方案1】:

    只需使用array_combine()

    Form::select('timezone', array_combine(DateTimeZone::listIdentifiers(), DateTimeZone::listIdentifiers()), $result->timezone])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 2020-03-19
      • 1970-01-01
      • 2014-07-06
      • 2018-11-21
      • 1970-01-01
      • 2017-03-12
      相关资源
      最近更新 更多