xref: /PHP-8.1/ext/filter/tests/060.phpt (revision 74859783)
1--TEST--
2filter_var() - tests for the range options of filter FILTER_VALIDATE_FLOAT
3--INI--
4precision=14
5--EXTENSIONS--
6filter
7--FILE--
8<?php
9
10$values = [
11    null,
12    false,
13    0,
14    -1,
15    '-5.4',
16    '-5.5',
17    '2,000.00',
18    '2,000.01',
19    '1,999.9999999'
20];
21
22var_dump(filter_var(
23    $values,
24    FILTER_VALIDATE_FLOAT,
25    [
26        'options' => [
27            'min_range' => -5.4,
28            'max_range' => 2000,
29        ],
30        'flags' => FILTER_FLAG_ALLOW_THOUSAND | FILTER_REQUIRE_ARRAY
31    ]
32));
33
34var_dump(filter_var(
35    '1000',
36    FILTER_VALIDATE_FLOAT,
37    [
38        'options' => [
39            'max_range' => 999.999,
40            'default' => 0
41        ]
42    ]
43));
44
45var_dump(filter_var(
46    '-11',
47    FILTER_VALIDATE_FLOAT,
48    [
49        'options' => [
50            'min_range' => -10,
51            'default' => 0
52        ]
53    ]
54));
55?>
56--EXPECT--
57array(9) {
58  [0]=>
59  bool(false)
60  [1]=>
61  bool(false)
62  [2]=>
63  float(0)
64  [3]=>
65  float(-1)
66  [4]=>
67  float(-5.4)
68  [5]=>
69  bool(false)
70  [6]=>
71  float(2000)
72  [7]=>
73  bool(false)
74  [8]=>
75  float(1999.9999999)
76}
77int(0)
78int(0)
79