1--TEST--
2Test 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
14echo "*** 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'
19var_dump( array_filter($input, 'is_int') );
20
21// using built-in function 'chr' as 'callback'
22var_dump( array_filter($input, 'chr') );
23
24// using language construct 'echo' as 'callback'
25var_dump( array_filter($input, 'echo') );
26
27// using language construct 'exit' as 'callback'
28var_dump( array_filter($input, 'exit') );
29
30echo "Done"
31?>
32--EXPECTF--
33*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***
34array(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
49Warning: chr() expects parameter 1 to be int, string given in %s on line %d
50array(8) {
51  [0]=>
52  int(0)
53  [1]=>
54  int(1)
55  [2]=>
56  int(-1)
57  [3]=>
58  int(10)
59  [4]=>
60  int(100)
61  [5]=>
62  int(1000)
63  [6]=>
64  string(5) "Hello"
65  [7]=>
66  NULL
67}
68
69Warning: array_filter() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
70NULL
71
72Warning: array_filter() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
73NULL
74Done
75