PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/array/array_unique_variation3.php

http://github.com/facebook/hiphop-php
PHP | 64 lines | 33 code | 13 blank | 18 comment | 0 complexity | 63bc154fa279e0be74d29221fe46a636 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. <?php
  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 keys to $input argument.
  9. */
  10. echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n";
  11. // get an unset variable
  12. $unset_var = 10;
  13. unset ($unset_var);
  14. // get a resource variable
  15. $fp = fopen(__FILE__, "r");
  16. // get a class
  17. class classA
  18. {
  19. public function __toString(){
  20. return "Class A object";
  21. }
  22. }
  23. // get a heredoc string
  24. $heredoc = <<<EOT
  25. Hello world
  26. EOT;
  27. // different associative arrays to be passed to $input argument
  28. $inputs = array (
  29. /*1*/ // arrays with integer keys
  30. array(0 => "0", 1 => "0"),
  31. array(1 => "1", 2 => "2", 3 => 1, 4 => "4"),
  32. // arrays with float keys
  33. /*3*/ array(2.3333 => "float", 44.44 => "float"),
  34. array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"),
  35. // arrays with string keys
  36. /*5*/ array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111),
  37. array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111),
  38. array("hello", $heredoc => "string", "string"),
  39. // array with object, unset variable and resource variable
  40. /*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"),
  41. );
  42. // loop through each sub-array of $inputs to check the behavior of array_unique()
  43. $iterator = 1;
  44. foreach($inputs as $input) {
  45. echo "-- Iteration $iterator --\n";
  46. var_dump( array_unique($input) );
  47. $iterator++;
  48. }
  49. fclose($fp);
  50. echo "Done";
  51. ?>