1--TEST--
2Test 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
9echo "*** 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;
31foreach ($arrays as $var_array ) {
32  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
33  var_dump( is_array ($var_array) );
34}
35
36echo "\n*** Testing is_array() on non array types ***\n";
37
38// get a resource type variable
39$fp = fopen (__FILE__, "r");
40$dfp = opendir ( dirname(__FILE__) );
41
42// unset variables
43$unset_array = array(10);
44unset($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;
96foreach ($varient_arrays as $type ) {
97  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
98  var_dump( is_array ($type) );
99}
100
101echo "\n*** Testing error conditions ***\n";
102//Zero argument
103var_dump( is_array() );
104
105//arguments more than expected
106var_dump( is_array ($fp, $fp) );
107
108echo "Done\n";
109/* close resources */
110fclose($fp);
111closedir($dfp);
112?>
113--EXPECTF--
114*** Testing is_array() on different type of arrays ***
115-- Iteration 1 --
116bool(true)
117-- Iteration 2 --
118bool(true)
119-- Iteration 3 --
120bool(true)
121-- Iteration 4 --
122bool(true)
123-- Iteration 5 --
124bool(true)
125-- Iteration 6 --
126bool(true)
127-- Iteration 7 --
128bool(true)
129-- Iteration 8 --
130bool(true)
131-- Iteration 9 --
132bool(true)
133-- Iteration 10 --
134bool(true)
135-- Iteration 11 --
136bool(true)
137-- Iteration 12 --
138bool(true)
139-- Iteration 13 --
140bool(true)
141-- Iteration 14 --
142bool(true)
143-- Iteration 15 --
144bool(true)
145
146*** Testing is_array() on non array types ***
147-- Iteration 1 --
148bool(false)
149-- Iteration 2 --
150bool(false)
151-- Iteration 3 --
152bool(false)
153-- Iteration 4 --
154bool(false)
155-- Iteration 5 --
156bool(false)
157-- Iteration 6 --
158bool(false)
159-- Iteration 7 --
160bool(false)
161-- Iteration 8 --
162bool(false)
163-- Iteration 9 --
164bool(false)
165-- Iteration 10 --
166bool(false)
167-- Iteration 11 --
168bool(false)
169-- Iteration 12 --
170bool(false)
171-- Iteration 13 --
172bool(false)
173-- Iteration 14 --
174bool(false)
175-- Iteration 15 --
176bool(false)
177-- Iteration 16 --
178bool(false)
179-- Iteration 17 --
180bool(false)
181-- Iteration 18 --
182bool(false)
183-- Iteration 19 --
184bool(false)
185-- Iteration 20 --
186bool(false)
187-- Iteration 21 --
188bool(false)
189-- Iteration 22 --
190bool(false)
191-- Iteration 23 --
192bool(false)
193-- Iteration 24 --
194bool(false)
195-- Iteration 25 --
196bool(false)
197-- Iteration 26 --
198bool(false)
199-- Iteration 27 --
200bool(false)
201-- Iteration 28 --
202bool(false)
203-- Iteration 29 --
204bool(false)
205
206*** Testing error conditions ***
207
208Warning: is_array() expects exactly 1 parameter, 0 given in %s on line %d
209bool(false)
210
211Warning: is_array() expects exactly 1 parameter, 2 given in %s on line %d
212bool(false)
213Done
214