【问题标题】:remove all options in drop down before this date在此日期之前删除下拉列表中的所有选项
【发布时间】:2016-08-23 03:14:37
【问题描述】:

我不是一个编码员,我需要修改以下代码以删除今天之前的所有选项,而不是仅显示数组中的 2 天。

add_filter('frm_setup_new_fields_vars', 'remove_field_option', 30, 2);
add_filter('frm_setup_edit_fields_vars', 'remove_field_option', 30, 2);
function remove_field_option( $values, $field ) {
  if ( $field->id == 242 ) { 
    $timestamp = time();
    $options_to_remove = array( '2016-08-19', '2016-08-20' )
    foreach ( $options_to_remove as $remove ) {
      $option_key = array_search( $remove, $values['options'] );
      if ( $option_key !== false ) {
        unset( $values['options'][ $option_key ] );
      }
    }
  }
  return $values;
}

【问题讨论】:

  • 您可以使用strtotime($time); 转换数组中的值,并取消设置任何小于您输入值的值。

标签: php function date formidable


【解决方案1】:

如果你想按照自己的方式使用 $options_remove 数组

$newArray = array_filter($oldArray,function($a) {
global $options_remove;
return !in_array($a,$options_remove);
});

或者类似的东西

$today  = mktime(0, 0, 0, date("m")  , date("d"), date("Y"));
 $newArray = array_filter($oldArray,function($a) {
// your old array assumed to hold the date or datetime as value such as '2016-08-11' or '2016-08-11 08:11:23'  
global $today;
return strtotime($a) < $today;
});

$newarray 在比今天开始时间短的时间内持有价值。所以直到昨天结束

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-21
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多