array_push_basic.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. Test array_push() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : int array_push(array $stack, mixed $var [, mixed $...])
  6. * Description: Pushes elements onto the end of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test basic functionality of array_push with indexed and associative arrays
  11. */
  12. echo "*** Testing array_push() : basic functionality ***\n";
  13. $array = array ('zero', 'one', 'two');
  14. $var1 = 'three';
  15. $var2 = 'four';
  16. echo "\n-- Push values onto an indexed array --\n";
  17. var_dump(array_push($array, $var1, $var2));
  18. var_dump($array);
  19. $array_assoc = array ('one' => 'un', 'two' => 'deux');
  20. echo "\n-- Push values onto an associative array --\n";
  21. var_dump(array_push($array_assoc, $var1, $var2));
  22. var_dump($array_assoc);
  23. echo "Done";
  24. ?>
  25. --EXPECT--
  26. *** Testing array_push() : basic functionality ***
  27. -- Push values onto an indexed array --
  28. int(5)
  29. array(5) {
  30. [0]=>
  31. string(4) "zero"
  32. [1]=>
  33. string(3) "one"
  34. [2]=>
  35. string(3) "two"
  36. [3]=>
  37. string(5) "three"
  38. [4]=>
  39. string(4) "four"
  40. }
  41. -- Push values onto an associative array --
  42. int(4)
  43. array(4) {
  44. ["one"]=>
  45. string(2) "un"
  46. ["two"]=>
  47. string(4) "deux"
  48. [0]=>
  49. string(5) "three"
  50. [1]=>
  51. string(4) "four"
  52. }
  53. Done