PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 68 lines | 40 code | 15 blank | 13 comment | 2 complexity | ed9acfe60ad2ce5e5325cfc550abf55e 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: int array_push( array &array );
  3. * Description: Push one or more elements onto the end of array
  4. and returns the new number of elements in the array.
  5. */
  6. $empty_array = array();
  7. $number = 5;
  8. $str = "abc";
  9. /* Various combinations of arrays to be used for the test */
  10. $mixed_array = array(
  11. array(),
  12. array( 1,2,3,4,5,6,7,8,9 ),
  13. array( "One", "_Two", "Three", "Four", "Five" ),
  14. array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ),
  15. array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ),
  16. array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ),
  17. array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ),
  18. array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF",
  19. "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ),
  20. array( 12, "name", 'age', '45' ),
  21. array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ),
  22. array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6,
  23. 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 )
  24. );
  25. /* Error Conditions */
  26. echo "\n*** Testing Error Conditions ***\n";
  27. /* Zero argument */
  28. var_dump( array_push() );
  29. /* Scalar argument */
  30. var_dump( array_push($number, 22) );
  31. /* String argument */
  32. var_dump( array_push($str, 22) );
  33. /* Invalid Number of arguments */
  34. var_dump( array_push($mixed_array[1],1,2) );
  35. /* Empty Array as argument */
  36. var_dump( array_push($empty_array, 2) );
  37. /* Loop to test normal functionality with different arrays inputs */
  38. echo "\n*** Testing with various array inputs ***\n";
  39. $counter = 1;
  40. foreach( $mixed_array as $sub_array )
  41. {
  42. echo "\n-- Input Array for Iteration $counter is --\n";
  43. print_r( $sub_array );
  44. echo "\nOutput after push is :\n";
  45. var_dump( array_push($sub_array, 22, "abc") );
  46. $counter++;
  47. }
  48. /* Checking for return value and the new array formed from push operation */
  49. echo "\n*** Checking for return value and the new array formed from push operation ***\n";
  50. var_dump( array_push($mixed_array[2], 22, 33, "44") );
  51. var_dump( $mixed_array[2] );
  52. echo"\nDone";
  53. ?>