xref: /PHP-7.1/ext/standard/tests/array/001.phpt (revision 29cfd6d2)
1--TEST--
2Test array_merge and array_walk
3--INI--
4precision=14
5--FILE--
6<?php
7require(dirname(__FILE__) . '/data.inc');
8/*
9** Create sample arrays
10** Test alpha, numeric (decimal, hex, octal) and special data
11**
12**
13*/
14
15/* Helper function to build testing arrays */
16function make_nested_array ($depth, $breadth, $function = NULL, $args = array ()) {
17    for ($x = 0; $x < $breadth; ++$x) {
18        if (NULL === $function) {
19            $array = array (0);
20        } else {
21            $array = array (call_user_func_array ($function, $args));
22        }
23        for ($y = 1; $y < $depth; ++$y) {
24            $array[0] = array ($array[0]);
25        }
26        $temp[$x] = $array;
27    }
28    return $temp;
29}
30
31/* Nested array */
32$data2 = make_nested_array (3, 3);
33$data = array_merge($data, $data2);
34
35var_dump ($data);
36
37function echo_kv ($value, $key) {
38    var_dump ($key);
39    var_dump ($value);
40}
41
42echo " -- Testing array_walk() -- \n";
43array_walk ($data, 'echo_kv');
44
45?>
46--EXPECT--
47array(11) {
48  [0]=>
49  string(3) "PHP"
50  [1]=>
51  string(27) "PHP: Hypertext Preprocessor"
52  [2]=>
53  string(4) "Test"
54  ["test"]=>
55  int(27)
56  [3]=>
57  string(4) "test"
58  [4]=>
59  array(2) {
60    [0]=>
61    string(6) "banana"
62    [1]=>
63    string(6) "orange"
64  }
65  [5]=>
66  string(6) "monkey"
67  [6]=>
68  float(-0.33333333333333)
69  [7]=>
70  array(1) {
71    [0]=>
72    array(1) {
73      [0]=>
74      array(1) {
75        [0]=>
76        int(0)
77      }
78    }
79  }
80  [8]=>
81  array(1) {
82    [0]=>
83    array(1) {
84      [0]=>
85      array(1) {
86        [0]=>
87        int(0)
88      }
89    }
90  }
91  [9]=>
92  array(1) {
93    [0]=>
94    array(1) {
95      [0]=>
96      array(1) {
97        [0]=>
98        int(0)
99      }
100    }
101  }
102}
103 -- Testing array_walk() --
104int(0)
105string(3) "PHP"
106int(1)
107string(27) "PHP: Hypertext Preprocessor"
108int(2)
109string(4) "Test"
110string(4) "test"
111int(27)
112int(3)
113string(4) "test"
114int(4)
115array(2) {
116  [0]=>
117  string(6) "banana"
118  [1]=>
119  string(6) "orange"
120}
121int(5)
122string(6) "monkey"
123int(6)
124float(-0.33333333333333)
125int(7)
126array(1) {
127  [0]=>
128  array(1) {
129    [0]=>
130    array(1) {
131      [0]=>
132      int(0)
133    }
134  }
135}
136int(8)
137array(1) {
138  [0]=>
139  array(1) {
140    [0]=>
141    array(1) {
142      [0]=>
143      int(0)
144    }
145  }
146}
147int(9)
148array(1) {
149  [0]=>
150  array(1) {
151    [0]=>
152    array(1) {
153      [0]=>
154      int(0)
155    }
156  }
157}
158