array_unshift_basic1.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test array_unshift() function : basic functionality - array with default keys for 'array' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
  6. * Description: Pushes elements onto the beginning of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Testing array_unshift() by giving array with default keys for $array argument
  11. */
  12. echo "*** Testing array_unshift() : basic functionality with default key array ***\n";
  13. // Initialise the array
  14. $array = array(1, 2);
  15. // Calling array_unshift() with default argument
  16. $temp_array = $array;
  17. // returns element count in the resulting array after arguments are pushed to
  18. // beginning of the given array
  19. var_dump( array_unshift($temp_array, 10) );
  20. // dump the resulting array
  21. var_dump($temp_array);
  22. // Calling array_unshift() with optional arguments
  23. $temp_array = $array;
  24. // returns element count in the resulting array after arguments are pushed to
  25. // beginning of the given array
  26. var_dump( array_unshift($temp_array, 222, "hello", 12.33) );
  27. // dump the resulting array
  28. var_dump($temp_array);
  29. echo "Done";
  30. ?>
  31. --EXPECTF--
  32. *** Testing array_unshift() : basic functionality with default key array ***
  33. int(3)
  34. array(3) {
  35. [0]=>
  36. int(10)
  37. [1]=>
  38. int(1)
  39. [2]=>
  40. int(2)
  41. }
  42. int(5)
  43. array(5) {
  44. [0]=>
  45. int(222)
  46. [1]=>
  47. string(5) "hello"
  48. [2]=>
  49. float(12.33)
  50. [3]=>
  51. int(1)
  52. [4]=>
  53. int(2)
  54. }
  55. Done