PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 79 lines | 50 code | 12 blank | 17 comment | 2 complexity | ddb16176962f729af0197e021c2fde7b 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* Passing different arrays to $input argument and testing whether
 9* array_unique() behaves in an expected way.
10*/
11<<__EntryPoint>> function main(): void {
12echo "*** Testing array_unique() : Passing different arrays to \$input argument ***\n";
13
14/* Different heredoc strings passed as argument to arrays */
15// heredoc with blank line
16$blank_line = <<<EOT
17
18
19EOT;
20
21// heredoc with multiline string
22$multiline_string = <<<EOT
23hello world
24The quick brown fox jumped over;
25the lazy dog
26This is a double quoted string
27EOT;
28
29// heredoc with different whitespaces
30$diff_whitespaces = <<<EOT
31hello\r world\t
321111\t\t != 2222\v\v
33heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
34EOT;
35
36// heredoc with quoted strings and numeric values
37$numeric_string = <<<EOT
3811 < 12. 123 >22
39'single quoted string'
40"double quoted string"
412222 != 1111.\t 0000 = 0000\n
42EOT;
43
44// arrays passed to $input argument
45$inputs = varray [
46/*1*/  varray[1, 2, 2, 1], // with default keys and numeric values
47       varray[1.1, 2.2, 1.1], // with default keys & float values
48       varray[false, true, false], // with default keys and boolean values
49       varray[], // empty array
50/*5*/  varray[NULL, null], // with NULL
51       varray["a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"],  // with double quoted strings
52       varray['a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'],  // with single quoted strings
53       darray["h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, 0 => $blank_line],  // with heredocs
54
55       // associative arrays
56/*9*/  darray[1 => "one", 2 => "two", 2 => "two"],  // explicit numeric keys, string values
57       darray["one" => 1, "two" => 2, "1" => 1 ],  // string keys & numeric values
58       darray[ 1 => 10, 2 => 20, 4 => 40, 5 => 10],  // explicit numeric keys and numeric values
59       darray[ "one" => "ten", "two" => "twenty", "10" => "ten"],  // string key/value
60       darray["one" => 1, 2 => "two", 4 => "four"],  //mixed
61
62       // associative array, containing null/empty/boolean values as key/value
63/*14*/ darray[NULL => "NULL", null => "null", "NULL" => NULL, "null" => null],
64       darray[true => "true", false => "false", "false" => false, "true" => true],
65       darray["" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''],
66       darray[1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true],
67/*18*/ darray['' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6],
68];
69
70// loop through each sub-array of $inputs to check the behavior of array_unique()
71$iterator = 1;
72foreach($inputs as $input) {
73  echo "-- Iteration $iterator --\n";
74  var_dump( array_unique($input, SORT_STRING) );
75  $iterator++;
76}
77
78echo "Done";
79}