PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
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. * Testing the functionality of array_unique() by passing different
  8. * associative arrays having different values to $input argument.
  9. */
  10. // get a class
  11. class classA
  12. {
  13. public function __toString() {
  14. return "Class A object";
  15. }
  16. }
  17. <<__EntryPoint>> function main(): void {
  18. echo "*** Testing array_unique() : assoc. array with diff. values to \$input argument ***\n";
  19. // get an unset variable
  20. $unset_var = 10;
  21. unset ($unset_var);
  22. // get a resource variable
  23. $fp = fopen(__FILE__, "r");
  24. // get a heredoc string
  25. $heredoc = <<<EOT
  26. Hello world
  27. EOT;
  28. // associative arrays with different values
  29. $inputs = varray [
  30. // arrays with integer values
  31. /*1*/ darray['0' => 0, '1' => 0],
  32. darray["one" => 1, 'two' => 2, "three" => 1, 4 => 1],
  33. // arrays with float values
  34. /*3*/ darray["float1" => 2.3333, "float2" => 2.3333],
  35. darray["f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2],
  36. // arrays with string values
  37. /*5*/ darray[111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"],
  38. darray[111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'],
  39. darray[1 => "hello", "heredoc" => $heredoc, 2 => $heredoc],
  40. // array with object, unset variable and resource variable
  41. /*8*/ darray[11 => new classA(), "unset" => @$unset_var, "resource" => $fp, 12 => new classA(), 13 => $fp],
  42. ];
  43. // loop through each sub-array of $inputs to check the behavior of array_unique()
  44. $iterator = 1;
  45. foreach($inputs as $input) {
  46. echo "-- Iteration $iterator --\n";
  47. var_dump( array_unique($input) );
  48. $iterator++;
  49. }
  50. fclose($fp);
  51. echo "Done";
  52. }