PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 64 lines | 34 code | 12 blank | 18 comment | 0 complexity | 06377630dcf519273616d01e3c9cf8a9 MD5 | raw file
 1<?hh
 2/* Prototype  : array array_unique(array $input)
 3 * Description: Removes duplicate values from array
 4 * Source code: ext/standard/array.c
 5*/
 6
 7/*
 8 * Testing the functionality of array_unique() by passing different
 9 * associative arrays having different values to $input argument.
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_unique() : assoc. array with diff. values to \$input argument ***\n";
21
22// get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// get a resource variable
27$fp = fopen(__FILE__, "r");
28
29// get a heredoc string
30$heredoc = <<<EOT
31Hello world
32EOT;
33
34// associative arrays with different values
35$inputs = varray [
36       // arrays with integer values
37/*1*/  darray['0' => 0, '1' => 0],
38       darray["one" => 1, 'two' => 2, "three" => 1, 4 => 1],
39
40       // arrays with float values
41/*3*/  darray["float1" => 2.3333, "float2" => 2.3333],
42       darray["f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2],
43
44       // arrays with string values
45/*5*/  darray[111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 =>  "\tHello"],
46       darray[111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 =>  '\tHello'],
47       darray[1 => "hello", "heredoc" => $heredoc, 2 => $heredoc],
48
49       // array with object, unset variable and resource variable
50/*8*/ darray[11 => new classA(), "unset" => @$unset_var, "resource" => $fp, 12 => new classA(), 13 => $fp],
51];
52
53// loop through each sub-array of $inputs to check the behavior of array_unique()
54$iterator = 1;
55foreach($inputs as $input) {
56  echo "-- Iteration $iterator --\n";
57  var_dump( array_unique($input) );
58  $iterator++;
59}
60
61fclose($fp);
62
63echo "Done";
64}