array_pad_variation4.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Test array_pad() function : usage variations - binary safe checking
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value)
  6. * Description: Returns a copy of input array padded with pad_value to size pad_size
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Passing binary values to $pad_value argument and testing whether
  11. * array_pad() behaves in an expected way with the other arguments passed to the function.
  12. * The $input and $pad_size arguments passed are fixed values.
  13. */
  14. echo "*** Testing array_pad() : Passing binary values to \$pad_value argument ***\n";
  15. // initialize the $input and $pad_size argument
  16. $input = array(1, 2, 3);
  17. $pad_size = 6;
  18. // initialize $pad_value with reference variable
  19. $binary = b"hello";
  20. var_dump( array_pad($input, $pad_size, $binary) ); // positive 'pad_size'
  21. var_dump( array_pad($input, -$pad_size, $binary) ); // negative 'pad_size'
  22. echo "Done";
  23. ?>
  24. --EXPECTF--
  25. *** Testing array_pad() : Passing binary values to $pad_value argument ***
  26. array(6) {
  27. [0]=>
  28. int(1)
  29. [1]=>
  30. int(2)
  31. [2]=>
  32. int(3)
  33. [3]=>
  34. string(5) "hello"
  35. [4]=>
  36. string(5) "hello"
  37. [5]=>
  38. string(5) "hello"
  39. }
  40. array(6) {
  41. [0]=>
  42. string(5) "hello"
  43. [1]=>
  44. string(5) "hello"
  45. [2]=>
  46. string(5) "hello"
  47. [3]=>
  48. int(1)
  49. [4]=>
  50. int(2)
  51. [5]=>
  52. int(3)
  53. }
  54. Done