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