小编Ram*_*leh的帖子

我可以在 php 过滤器中直接得到这个吗(FILTER_REQUIRE_ARRAY、FILTER_REQUIRE_SCALAR、FILTER_FORCE_ARRAY)

3 个 php 常量,我不确定它们是做什么的

1. FILTER_REQUIRE_ARRAY

The name says it all I can agree no more but there is a function called
<em>filter_var/input_array()</em> which works in similar fashion; 
I've seen examples where recursive validation is required but 
not all element in the array are arrays some items are just scalar value 
Run Code Online (Sandbox Code Playgroud)




FILTER_REQUIRE_SCALAR

    <?php 
        $x = 5;
        $y = [1, 2, 3];

        var_dump(filter_var($x,FILTER_REQUIRE_SCALAR));
        var_dump(filter_var($y,FILTER_REQUIRE_SCALAR));
    ?>
Run Code Online (Sandbox Code Playgroud)

考虑产生

bool(false)
bool(false)
as use的 prev code可以看到$x 确实是 标量


FILTER_FORCE_ARRAY

总是返回一个数组这是phpDoc …

php filtering

3
推荐指数
1
解决办法
1547
查看次数

标签 统计

filtering ×1

php ×1