PageRenderTime 96ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/tstarling/hiphop-php
PHP | 99 lines | 56 code | 21 blank | 22 comment | 0 complexity | 74c8ba726b3de26b7cd857fa2fb26c29 MD5 | raw file
  1. <?php
  2. /* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...])
  3. * Description: Returns the entries of arr1 that have keys which are present in all the other arguments.
  4. * Source code: ext/standard/array.c
  5. */
  6. echo "*** Testing array_intersect_key() : usage variation ***\n";
  7. // Initialise function arguments not being substituted (if any)
  8. $array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
  9. $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
  10. //get an unset variable
  11. $unset_var = 10;
  12. unset ($unset_var);
  13. //resource variable
  14. $fp = fopen(__FILE__, "r");
  15. // define some classes
  16. class classWithToString
  17. {
  18. public function __toString() {
  19. return "Class A object";
  20. }
  21. }
  22. class classWithoutToString
  23. {
  24. }
  25. // heredoc string
  26. $heredoc = <<<EOT
  27. hello world
  28. EOT;
  29. // add arrays
  30. $index_array = array (1, 2, 3);
  31. $assoc_array = array ('one' => 1, 'two' => 2);
  32. //array of values to iterate over
  33. $inputs = array(
  34. // int data
  35. 'int 0' => 0,
  36. 'int 1' => 1,
  37. 'int 12345' => 12345,
  38. 'int -12345' => -12345,
  39. // float data
  40. 'float 10.5' => 10.5,
  41. 'float -10.5' => -10.5,
  42. 'float 12.3456789000e10' => 12.3456789000e10,
  43. 'float -12.3456789000e10' => -12.3456789000e10,
  44. 'float .5' => .5,
  45. // null data
  46. 'uppercase NULL' => NULL,
  47. 'lowercase null' => null,
  48. // boolean data
  49. 'lowercase true' => true,
  50. 'lowercase false' =>false,
  51. 'uppercase TRUE' =>TRUE,
  52. 'uppercase FALSE' =>FALSE,
  53. // empty data
  54. 'empty string DQ' => "",
  55. 'empty string SQ' => '',
  56. // string data
  57. 'string DQ' => "string",
  58. 'string SQ' => 'string',
  59. 'mixed case string' => "sTrInG",
  60. 'heredoc' => $heredoc,
  61. // object data
  62. 'instance of classWithToString' => new classWithToString(),
  63. 'instance of classWithoutToString' => new classWithoutToString(),
  64. // undefined data
  65. 'undefined var' => @$undefined_var,
  66. // unset data
  67. 'unset var' => @$unset_var,
  68. // resource data
  69. 'resource var' => $fp,
  70. );
  71. // loop through each element of the array for arr2
  72. foreach($inputs as $key =>$value) {
  73. echo "\n--$key--\n";
  74. var_dump( array_intersect_key($array1, $array2, $value) );
  75. }
  76. fclose($fp);
  77. ?>
  78. ===DONE===