Annotation of embedaddon/php/ext/standard/tests/array/array_filter_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_filter() function : usage variations - built-in functions as 'callback' argument
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 built-in functions and different language constructs as 'callback' argument
12: */
13:
14: echo "*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***\n";
15:
16: $input = array(0, 1, -1, 10, 100, 1000, 'Hello', null);
17:
18: // using built-in function 'is_int' as 'callback'
19: var_dump( array_filter($input, 'is_int') );
20:
21: // using built-in function 'chr' as 'callback'
22: var_dump( array_filter($input, 'chr') );
23:
24: // using language construct 'echo' as 'callback'
25: var_dump( array_filter($input, 'echo') );
26:
27: // using language construct 'exit' as 'callback'
28: var_dump( array_filter($input, 'exit') );
29:
30: echo "Done"
31: ?>
32: --EXPECTF--
33: *** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***
34: array(6) {
35: [0]=>
36: int(0)
37: [1]=>
38: int(1)
39: [2]=>
40: int(-1)
41: [3]=>
42: int(10)
43: [4]=>
44: int(100)
45: [5]=>
46: int(1000)
47: }
48: array(8) {
49: [0]=>
50: int(0)
51: [1]=>
52: int(1)
53: [2]=>
54: int(-1)
55: [3]=>
56: int(10)
57: [4]=>
58: int(100)
59: [5]=>
60: int(1000)
61: [6]=>
62: string(5) "Hello"
63: [7]=>
64: NULL
65: }
66:
67: Warning: array_filter() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
68: NULL
69:
70: Warning: array_filter() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
71: NULL
72: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>