summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/sizeof_variation2.phpt
blob: baa917a299ee66d9e7b77b23a25461aa22bc246e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
--TEST--
Test sizeof() function : usage variations - different array values for 'var' argument
--FILE--
<?php
echo "*** Testing sizeof() : usage variations ***\n";

// get a resource variable
$fp = fopen(__FILE__, "r");

echo "--- Testing sizeof() with different array values for 'var' argument ---\n";

// array containing different types of array values for 'var' argument
$values = array (
  /* 1  */  array($fp, "resource" => $fp),
            array(1, array(3, 4, array(6, array(8)))),
            array("a" => 1, 'b' => 2, array( "c" =>3, array( "d" => 5))),
            array(),
  /* 5  */  array(1, 2, 3, 4),
            array("Saffron", "White", "Green"),
            array('saffron', 'white', 'green'),
            array(1 => "Hi", 2 => "Hello" ),
            array("color" => "red", "item" => "pen"),
  /* 10 */  array('color' => 'red', 'item' => 'pen'),
            array(TRUE => "red", FALSE => "pen" ),
            array(false => 'red', true => 'pen' ),
            array('color' => "red", "item" => 'pen', 1 => "Hi", "" => "Hello" ),
  /* 14 */  array($fp, "resource1" => $fp, 'resource2' => $fp, array( $fp, 'type' => $fp) )
);

// loop through each element of the values array for 'var' argument
// check the working of sizeof()
$counter = 1;
for($i = 0; $i < count($values); $i++)
{
  echo "-- Iteration $counter --\n";
  $var = $values[$i];

  echo "Default Mode: ";
  var_dump( sizeof($var) );
  echo "\n";

  echo "COUNT_NORMAL Mode: ";
  var_dump( sizeof($var, COUNT_NORMAL) );
  echo "\n";

  echo "COUNT_RECURSIVE Mode: ";
  var_dump( sizeof($var, COUNT_RECURSIVE) );
  echo "\n";

  $counter++;
}

echo "Done";
?>
--EXPECT--
*** Testing sizeof() : usage variations ***
--- Testing sizeof() with different array values for 'var' argument ---
-- Iteration 1 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 2 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(8)

-- Iteration 3 --
Default Mode: int(3)

COUNT_NORMAL Mode: int(3)

COUNT_RECURSIVE Mode: int(6)

-- Iteration 4 --
Default Mode: int(0)

COUNT_NORMAL Mode: int(0)

COUNT_RECURSIVE Mode: int(0)

-- Iteration 5 --
Default Mode: int(4)

COUNT_NORMAL Mode: int(4)

COUNT_RECURSIVE Mode: int(4)

-- Iteration 6 --
Default Mode: int(3)

COUNT_NORMAL Mode: int(3)

COUNT_RECURSIVE Mode: int(3)

-- Iteration 7 --
Default Mode: int(3)

COUNT_NORMAL Mode: int(3)

COUNT_RECURSIVE Mode: int(3)

-- Iteration 8 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 9 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 10 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 11 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 12 --
Default Mode: int(2)

COUNT_NORMAL Mode: int(2)

COUNT_RECURSIVE Mode: int(2)

-- Iteration 13 --
Default Mode: int(4)

COUNT_NORMAL Mode: int(4)

COUNT_RECURSIVE Mode: int(4)

-- Iteration 14 --
Default Mode: int(4)

COUNT_NORMAL Mode: int(4)

COUNT_RECURSIVE Mode: int(6)

Done