PHP字段下拉列表值从08-17改为00-17
我对php一无所知,非常感谢您的帮助。我有这个代码,我希望下拉字段显示08到17之间的值(所以:08,09,10,11,12,13,14,15,16,17)。现在显示从00到17。有人能帮我修一下吗 代码如下:PHP字段下拉列表值从08-17改为00-17,php,html,field,options,Php,Html,Field,Options,我对php一无所知,非常感谢您的帮助。我有这个代码,我希望下拉字段显示08到17之间的值(所以:08,09,10,11,12,13,14,15,16,17)。现在显示从00到17。有人能帮我修一下吗 代码如下: // hours $string .= ' <option value=""></option>' . "\n"; $tf_hours = (self::$form_options['time_format'] == '24') ?
// hours
$string .= ' <option value=""></option>' . "\n";
$tf_hours = (self::$form_options['time_format'] == '24') ? '17' : '12';
for ( $keyi = (self::$form_options['time_format'] == '24') ? 0 : 1; $keyi <= $tf_hours; $keyi++ ) {
$keyi = sprintf( "%02d", $keyi );
if ( self::$form_content[$field['slug']]['h'] != '' ) {
if ( self::$form_content[$field['slug']]['h'] == "$keyi" ) {
$selected = ' selected="selected"';
}
}
$string .= ' <option value="' . esc_attr( $keyi ) . '"' . $selected . '>' . esc_html( $keyi ) . '</option>' . "\n";
$selected = '';
}
$string .= " </select>:\n <select ";
$string .= ($field['input_css'] != '') ? self::convert_css( $field['input_css'] ) : self::get_this_css('select_style');
$string .= ' id="fscf_field' . self::$form_id_num . '_' . $key . 'm" name="' . $field['slug'] . '[m]">' . "\n";
$selected = '';
//小时
$string.=''。“\n”;
$tf_hours=(self::$form_options['time_format']='24')?'17' : '12';
对于($keyi=(self::$form\u options['time\u format']='24')?0:1;$keyiChange
for($keyi=(self:$form\u options['time\u format']='24')?0:1;$keyi我认为从您当前的输出来看,self:$form\u options['time\u format']
设置为24。
for循环的语法是
for (expr1; expr2; expr3)
statement
此处,在循环开始时执行expr1
一次,如果expr2
的计算结果为TRUE
则执行该语句,expr3
在每次迭代的结束时进行计算
现在请参见下面的代码:
$tf_hours = (self::$form_options['time_format'] == '24') ? '17' : '12';
上述代码的作用是,如果时间格式为24,则将$tf_hours
设置为17,如果不是,则设置为12
for ( $keyi = (self::$form_options['time_format'] == '24') ? 0 : 1; $keyi <= $tf_hours; $keyi++ ) {
希望这对你有帮助。嗯,你可能想考虑使用模板库…
$tf_hours = (self::$form_options['time_format'] == '24') ? '17' : '12';
for ( $keyi = (self::$form_options['time_format'] == '24') ? 0 : 1; $keyi <= $tf_hours; $keyi++ ) {
for ( $keyi = (self::$form_options['time_format'] == '24') ? 8 : 1; $keyi <= $tf_hours; $keyi++ ) {