summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_filter_variation6.phpt
blob: 2e7ea77dca2d6bd13ef07594cd6c9c7e78bb502e (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
--TEST--
Test array_filter() function : usage variations - 'input' array containing references 
--FILE--
<?php
/* Prototype  : array array_filter(array $input [, callback $callback])
 * Description: Filters elements from the array via the callback. 
 * Source code: ext/standard/array.c
*/

/*
* Passing 'input' array which contains elements as reference to other data
*/

echo "*** Testing array_filter() : usage variations - 'input' containing references ***\n";

// Callback function
/* Prototype : bool callback(array $input)
 * Parameter : $input - array of which each element need to be checked in function
 * Return Type : returns true or false
 * Description : This function checks each element of an input array if element > 5 then
 * returns true else returns false
 */
function callback($input)
{
  if($input > 5) {
    return true;
  }
  else {
    return false;
  }
}
  
// initializing variables
$value1 = array(1, 2, 8);
$value2 = array(5, 6, 4);
$input = array(&$value1, 10, &$value2, 'value');

// with 'callback' argument
var_dump( array_filter($input, 'callback') );

// with default 'callback' argument
var_dump( array_filter($input) ); 

echo "Done"
?>
--EXPECT--
*** Testing array_filter() : usage variations - 'input' containing references ***
array(3) {
  [0]=>
  &array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(8)
  }
  [1]=>
  int(10)
  [2]=>
  &array(3) {
    [0]=>
    int(5)
    [1]=>
    int(6)
    [2]=>
    int(4)
  }
}
array(4) {
  [0]=>
  &array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(8)
  }
  [1]=>
  int(10)
  [2]=>
  &array(3) {
    [0]=>
    int(5)
    [1]=>
    int(6)
    [2]=>
    int(4)
  }
  [3]=>
  string(5) "value"
}
Done