Annotation of embedaddon/php/ext/standard/tests/array/array_filter_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_filter() function : usage variations - 'input' array containing references
3: --FILE--
4: <?php
5: /* Prototype : array array_filter(array $input [, callback $callback])
6: * Description: Filters elements from the array via the callback.
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Passing 'input' array which contains elements as reference to other data
12: */
13:
14: echo "*** Testing array_filter() : usage variations - 'input' containing references ***\n";
15:
16: // Callback function
17: /* Prototype : bool callback(array $input)
18: * Parameter : $input - array of which each element need to be checked in function
19: * Return Type : returns true or false
20: * Description : This function checks each element of an input array if element > 5 then
21: * returns true else returns false
22: */
23: function callback($input)
24: {
25: if($input > 5) {
26: return true;
27: }
28: else {
29: return false;
30: }
31: }
32:
33: // initializing variables
34: $value1 = array(1, 2, 8);
35: $value2 = array(5, 6, 4);
36: $input = array(&$value1, 10, &$value2, 'value');
37:
38: // with 'callback' argument
39: var_dump( array_filter($input, 'callback') );
40:
41: // with default 'callback' argument
42: var_dump( array_filter($input) );
43:
44: echo "Done"
45: ?>
46: --EXPECTF--
47: *** Testing array_filter() : usage variations - 'input' containing references ***
48: array(3) {
49: [0]=>
50: &array(3) {
51: [0]=>
52: int(1)
53: [1]=>
54: int(2)
55: [2]=>
56: int(8)
57: }
58: [1]=>
59: int(10)
60: [2]=>
61: &array(3) {
62: [0]=>
63: int(5)
64: [1]=>
65: int(6)
66: [2]=>
67: int(4)
68: }
69: }
70: array(4) {
71: [0]=>
72: &array(3) {
73: [0]=>
74: int(1)
75: [1]=>
76: int(2)
77: [2]=>
78: int(8)
79: }
80: [1]=>
81: int(10)
82: [2]=>
83: &array(3) {
84: [0]=>
85: int(5)
86: [1]=>
87: int(6)
88: [2]=>
89: int(4)
90: }
91: [3]=>
92: string(5) "value"
93: }
94: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>