PageRenderTime 56ms CodeModel.GetById 48ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/array/array_diff_variation8.php

http://github.com/facebook/hiphop-php
PHP | 67 lines | 36 code | 13 blank | 18 comment | 0 complexity | 54ffc9e0b5e34caf32bd55f7d6f2e34f MD5 | raw file
 1<?hh
 2/* Prototype  : array array_diff(array $arr1, array $arr2 [, array ...])
 3 * Description: Returns the entries of $arr1 that have values which are
 4 * not present in any of the others arguments.
 5 * Source code: ext/standard/array.c
 6 */
 7
 8/*
 9 * Test array_diff() with associative arrays containing different data types as values
10 */
11
12// get a class
13class classA
14{
15  public function __toString() {
16     return "Class A object";
17  }
18}
19<<__EntryPoint>> function main(): void {
20echo "*** Testing array_diff() : usage variations ***\n";
21
22$array = darray['a' => '1', 'b' => '2', 'c' => '3'];
23
24// get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// get a resource variable
29$fp = fopen(__FILE__, "r");
30
31// get a heredoc string
32$heredoc = <<<EOT
33Hello world
34EOT;
35
36// associative arrays with different values
37$inputs = varray [
38       // arrays with integer values
39/*1*/  darray['0' => 0, '1' => 0],
40       darray["one" => 1, 'two' => 2, "three" => 1, 4 => 1],
41
42       // arrays with float values
43/*3*/  darray["float1" => 2.3333, "float2" => 2.3333],
44       darray["f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2],
45
46       // arrays with string values
47/*5*/  darray[111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 =>  "\tHello"],
48       darray[111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 =>  '\tHello'],
49       darray[1 => "hello", "heredoc" => $heredoc, 2 => $heredoc],
50
51       // array with object, unset variable and resource variable
52/*8*/ darray[11 => new classA(), "unset" => @$unset_var, "resource" => $fp, 12 => new classA(), 13 => $fp],
53];
54
55// loop through each sub-array of $inputs to check the behavior of array_unique()
56$iterator = 1;
57foreach($inputs as $input) {
58  echo "-- Iteration $iterator --\n";
59  var_dump( array_diff($array, $input) );
60  var_dump( array_diff($input, $array) );
61  $iterator++;
62}
63
64fclose($fp);
65
66echo "Done";
67}