]> granicus.if.org Git - php/blob
200ecbd6ac
[php] /
1 --TEST--
2 Test is_array() function
3 --FILE--
4 <?php
5 /* Prototype: bool is_array ( mixed $var );
6  * Description: Finds whether the given variable is an array
7  */
8
9 echo "*** Testing is_array() on different type of arrays ***\n";
10 /* different types of arrays */
11 $arrays = array(
12   array(),
13   array(NULL),
14   array(null),
15   array(true),
16   array(""),
17   array(''),
18   array(array(), array()),
19   array(array(1, 2), array('a', 'b')),
20   array(1 => 'One'),
21   array("test" => "is_array"),
22   array(0),
23   array(-1),
24   array(10.5, 5.6),
25   array("string", "test"),
26   array('string', 'test')
27 );
28 /* loop to check that is_array() recognizes different
29    type of arrays, expected output bool(true) */
30 $loop_counter = 1;
31 foreach ($arrays as $var_array ) {
32   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
33   var_dump( is_array ($var_array) );
34 }
35
36 echo "\n*** Testing is_array() on non array types ***\n";
37
38 // get a resource type variable
39 $fp = fopen (__FILE__, "r");
40 $dfp = opendir ( __DIR__ );
41
42 // unset variables
43 $unset_array = array(10);
44 unset($unset_array);
45
46 // other types in a array
47 $varient_arrays = array (
48   /* integers */
49   543915,
50   -5322,
51   0x55F,
52   -0xCCF,
53   123,
54   -0654,
55
56   /* strings */
57   "",
58   '',
59   "0",
60   '0',
61   'string',
62   "string",
63
64   /* floats */
65   10.0000000000000000005,
66   .5e6,
67   -.5E7,
68   .5E+8,
69   -.5e+90,
70   1e5,
71
72   /* objects */
73   new stdclass,
74
75   /* resources */
76   $fp,
77   $dfp,
78
79   /* nulls */
80   null,
81   NULL,
82
83   /* boolean */
84   true,
85   TRUE,
86   FALSE,
87   false,
88
89   /* unset/undefined arrays  */
90   @$unset_array,
91   @$undefined_array
92 );
93 /* loop through the $varient_array to see working of
94    is_array() on non array types, expected output bool(false) */
95 $loop_counter = 1;
96 foreach ($varient_arrays as $type ) {
97   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
98   var_dump( is_array ($type) );
99 }
100
101 echo "Done\n";
102 /* close resources */
103 fclose($fp);
104 closedir($dfp);
105 ?>
106 --EXPECTF--
107 *** Testing is_array() on different type of arrays ***
108 -- Iteration 1 --
109 bool(true)
110 -- Iteration 2 --
111 bool(true)
112 -- Iteration 3 --
113 bool(true)
114 -- Iteration 4 --
115 bool(true)
116 -- Iteration 5 --
117 bool(true)
118 -- Iteration 6 --
119 bool(true)
120 -- Iteration 7 --
121 bool(true)
122 -- Iteration 8 --
123 bool(true)
124 -- Iteration 9 --
125 bool(true)
126 -- Iteration 10 --
127 bool(true)
128 -- Iteration 11 --
129 bool(true)
130 -- Iteration 12 --
131 bool(true)
132 -- Iteration 13 --
133 bool(true)
134 -- Iteration 14 --
135 bool(true)
136 -- Iteration 15 --
137 bool(true)
138
139 *** Testing is_array() on non array types ***
140 -- Iteration 1 --
141 bool(false)
142 -- Iteration 2 --
143 bool(false)
144 -- Iteration 3 --
145 bool(false)
146 -- Iteration 4 --
147 bool(false)
148 -- Iteration 5 --
149 bool(false)
150 -- Iteration 6 --
151 bool(false)
152 -- Iteration 7 --
153 bool(false)
154 -- Iteration 8 --
155 bool(false)
156 -- Iteration 9 --
157 bool(false)
158 -- Iteration 10 --
159 bool(false)
160 -- Iteration 11 --
161 bool(false)
162 -- Iteration 12 --
163 bool(false)
164 -- Iteration 13 --
165 bool(false)
166 -- Iteration 14 --
167 bool(false)
168 -- Iteration 15 --
169 bool(false)
170 -- Iteration 16 --
171 bool(false)
172 -- Iteration 17 --
173 bool(false)
174 -- Iteration 18 --
175 bool(false)
176 -- Iteration 19 --
177 bool(false)
178 -- Iteration 20 --
179 bool(false)
180 -- Iteration 21 --
181 bool(false)
182 -- Iteration 22 --
183 bool(false)
184 -- Iteration 23 --
185 bool(false)
186 -- Iteration 24 --
187 bool(false)
188 -- Iteration 25 --
189 bool(false)
190 -- Iteration 26 --
191 bool(false)
192 -- Iteration 27 --
193 bool(false)
194 -- Iteration 28 --
195 bool(false)
196 -- Iteration 29 --
197 bool(false)
198 Done