join_basic.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test join() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : string join( string $glue, array $pieces )
  6. * Description: Join array elements with a string
  7. * Source code: ext/standard/string.c
  8. * Alias of function: implode()
  9. */
  10. echo "*** Testing join() : basic functionality ***\n";
  11. // Initialize all required variables
  12. $glue = ',';
  13. $pieces = array(1, 2, 3, 4);
  14. // pieces as arry with numeric values
  15. var_dump( join($glue, $pieces) );
  16. // pieces as array with strings values
  17. $glue = ", "; // multiple car as glue
  18. $pieces = array("Red", "Green", "Blue", "Black", "White");
  19. var_dump( join($glue, $pieces) );
  20. // pices as associative array (numeric values)
  21. $pieces = array("Hour" => 10, "Minute" => 20, "Second" => 40);
  22. $glue = ':';
  23. var_dump( join($glue, $pieces) );
  24. // pices as associative array (string/numeric values)
  25. $pieces = array("Day" => 'Friday', "Month" => "September", "Year" => 2007);
  26. $glue = '/';
  27. var_dump( join($glue, $pieces) );
  28. echo "Done\n";
  29. ?>
  30. --EXPECTF--
  31. *** Testing join() : basic functionality ***
  32. string(7) "1,2,3,4"
  33. string(30) "Red, Green, Blue, Black, White"
  34. string(8) "10:20:40"
  35. string(21) "Friday/September/2007"
  36. Done