doudu22272099831 2017-03-29 17:16
浏览 125
已采纳

使用PHP filter_var_array(),为什么FILTER_CALLBACK将函数参数转换为字符串?

In the following code, why does the callback function cast the $value argument as string?

$post_values = $_POST['dates'];
/*
var_dump of $post_values
array(1) { [0]=> array(3) { ["date"]=> string(10) "2016-05-10" ["starttime"]=> string(5) "12:30" ["endtime"]=> string(5) "14:33" } }
*/



$args = [
  'dates' => [
    'filter' => FILTER_CALLBACK,
    'options' => function ($value) {
      // The $value here has been cast to string. Why?
      // $value now has value of: string(10) "2016-05-10".
      // I expect it to be an array.
      return $value;
    }
  ]
];


$filtered_values = filter_var_array($post_values, $args);
  • 写回答

2条回答 默认 最新

  • duanou9739 2018-10-30 14:01
    关注

    This is normal behavior of filter_var() and filter_var_array() functions. Official documentation of filter_var() variable parameter contains explanation:

    Note that scalar values are converted to string internally before they are filtered.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵