sync the repo
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / array_diff_key_variation1.php
blob57a5deaa7e3d986569b3559f28f512d70faa4c82
1 <?hh
2 /* Prototype : array array_diff_key(array arr1, array arr2 [, array ...])
3 * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments.
4 * Source code: ext/standard/array.c
5 */
7 // define some classes
8 class classWithToString
10 public function __toString() :mixed{
11 return "Class A object";
15 class classWithoutToString
18 <<__EntryPoint>> function main(): void {
19 echo "*** Testing array_diff_key() : usage variation ***\n";
21 // Initialise function arguments not being substituted (if any)
22 $array2 = dict['green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8];
23 $array3 = vec[1, 2, 3, 4, 5];
26 //resource variable
27 $fp = fopen(__FILE__, "r");
29 // heredoc string
30 $heredoc = <<<EOT
31 hello world
32 EOT;
34 //array of values to iterate over
35 $inputs = dict[
37 // int data
38 'int 0' => 0,
39 'int 1' => 1,
40 'int 12345' => 12345,
41 'int -12345' => -12345,
43 // float data
44 'float 10.5' => 10.5,
45 'float -10.5' => -10.5,
46 'float 12.3456789000e10' => 12.3456789000e10,
47 'float -12.3456789000e10' => -12.3456789000e10,
48 'float .5' => .5,
50 // null data
51 'uppercase NULL' => NULL,
52 'lowercase null' => null,
54 // boolean data
55 'lowercase true' => true,
56 'lowercase false' =>false,
57 'uppercase TRUE' =>TRUE,
58 'uppercase FALSE' =>FALSE,
60 // empty data
61 'empty string DQ' => "",
62 'empty string SQ' => '',
64 // string data
65 'string DQ' => "string",
66 'string SQ' => 'string',
67 'mixed case string' => "sTrInG",
68 'heredoc' => $heredoc,
70 // object data
71 'instance of classWithToString' => new classWithToString(),
72 'instance of classWithoutToString' => new classWithoutToString(),
76 // resource data
77 'resource' => $fp,
80 // loop through each element of the array for arr1
81 foreach($inputs as $key =>$value) {
82 echo "\n--$key--\n";
83 var_dump( array_diff_key($value, $array2) );
84 var_dump( array_diff_key($value, $array2, $array3) );
87 fclose($fp);
88 echo "===DONE===\n";