~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/standard/tests/array/array_filter_variation5.phpt

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
Test array_filter() function : usage variations - 'input' argument with different false entries
 
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
* With default callback function argument, array_filter() removes elements which are interpreted as false 
 
12
* Here Testing all the false array element possibilities
 
13
*/
 
14
 
 
15
// callback function always_true
 
16
function always_true($input)
 
17
{
 
18
  return true;
 
19
}
 
20
 
 
21
// callback function always_false
 
22
function always_false($input)
 
23
{
 
24
  return false;
 
25
}
 
26
 
 
27
echo "*** Testing array_filter() : usage variations - different false elements in 'input' ***\n";
 
28
 
 
29
// unset variable
 
30
$unset_var = 10;
 
31
unset($unset_var);
 
32
 
 
33
// empty heredoc string
 
34
$empty_heredoc =<<<EOT
 
35
EOT;
 
36
 
 
37
// input array with different false elements
 
38
$input = array(
 
39
  false,
 
40
  False,
 
41
  '',
 
42
  "",
 
43
  0,
 
44
  0.0,
 
45
  null,
 
46
  NULL,
 
47
  "0",
 
48
  '0',
 
49
  array(),
 
50
  !1,
 
51
  1==2,
 
52
  $empty_heredoc,
 
53
  @$unset_var,
 
54
  @$undefined_var,
 
55
);
 
56
 
 
57
// With default callback function
 
58
var_dump( array_filter($input) );  
 
59
 
 
60
// With callback function which returns always true
 
61
var_dump( array_filter($input, 'always_true') ); 
 
62
 
 
63
// With callback function which returns always false
 
64
var_dump( array_filter($input, 'always_false') );  
 
65
 
 
66
echo "Done"
 
67
?>
 
68
--EXPECTF--
 
69
*** Testing array_filter() : usage variations - different false elements in 'input' ***
 
70
array(0) {
 
71
}
 
72
array(16) {
 
73
  [0]=>
 
74
  bool(false)
 
75
  [1]=>
 
76
  bool(false)
 
77
  [2]=>
 
78
  string(0) ""
 
79
  [3]=>
 
80
  string(0) ""
 
81
  [4]=>
 
82
  int(0)
 
83
  [5]=>
 
84
  float(0)
 
85
  [6]=>
 
86
  NULL
 
87
  [7]=>
 
88
  NULL
 
89
  [8]=>
 
90
  string(1) "0"
 
91
  [9]=>
 
92
  string(1) "0"
 
93
  [10]=>
 
94
  array(0) {
 
95
  }
 
96
  [11]=>
 
97
  bool(false)
 
98
  [12]=>
 
99
  bool(false)
 
100
  [13]=>
 
101
  string(0) ""
 
102
  [14]=>
 
103
  NULL
 
104
  [15]=>
 
105
  NULL
 
106
}
 
107
array(0) {
 
108
}
 
109
Done