1--TEST--
2Test join() function : usage variations - different values for 'pieces' argument
3--FILE--
4<?php
5/*
6 * test join() by giving different pieces values
7*/
8
9echo "*** Testing join() : usage variations ***\n";
10
11$pieces_arrays = array (
12  array(1, 2), // array with default keys and numrice values
13  array(1.1, 2.2), // array with default keys & float values
14  array( array(2), array(1)), // sub arrays
15  array(false,true), // array with default keys and boolean values
16  array(), // empty array
17  array(NULL), // array with NULL
18  array("a","aaaa","b","bbbb","c","ccccc"),
19
20  // associative arrays
21  array(1 => "one", 2 => "two", 3 => "three"),  // explicit numeric keys, string values
22  array("one" => 1, "two" => 2, "three" => 3 ),  // string keys & numeric values
23  array( 1 => 10, 2 => 20, 4 => 40, 3 => 30),  // explicit numeric keys and numeric values
24  array( "one" => "ten", "two" => "twenty", "three" => "thirty"),  // string key/value
25  array("one" => 1, 2 => "two", 4 => "four"),  //mixed
26
27  // associative array, containing null/empty/boolean values as key/value
28  array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
29  array(true => "true", false => "false", "false" => false, "true" => true),
30  array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
31  array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
32  array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
33
34  // array with repetitive keys
35  array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
36);
37
38// a multichar glue value
39$glue = "], [";
40
41// loop through each $pieces_arrays element and call join()
42$iteration = 1;
43for($index = 0; $index < count($pieces_arrays); $index ++) {
44  echo "-- Iteration $iteration --\n";
45  var_dump( join($glue, $pieces_arrays[$index]) );
46  $iteration ++;
47}
48
49echo "Done\n";
50?>
51--EXPECTF--
52*** Testing join() : usage variations ***
53-- Iteration 1 --
54string(6) "1], [2"
55-- Iteration 2 --
56string(10) "1.1], [2.2"
57-- Iteration 3 --
58
59Warning: Array to string conversion in %s on line %d
60
61Warning: Array to string conversion in %s on line %d
62string(14) "Array], [Array"
63-- Iteration 4 --
64string(5) "], [1"
65-- Iteration 5 --
66string(0) ""
67-- Iteration 6 --
68string(0) ""
69-- Iteration 7 --
70string(36) "a], [aaaa], [b], [bbbb], [c], [ccccc"
71-- Iteration 8 --
72string(19) "one], [two], [three"
73-- Iteration 9 --
74string(11) "1], [2], [3"
75-- Iteration 10 --
76string(20) "10], [20], [40], [30"
77-- Iteration 11 --
78string(23) "ten], [twenty], [thirty"
79-- Iteration 12 --
80string(16) "1], [two], [four"
81-- Iteration 13 --
82string(12) "null], [], ["
83-- Iteration 14 --
84string(22) "true], [false], [], [1"
85-- Iteration 15 --
86string(14) "emptys], [], ["
87-- Iteration 16 --
88string(21) "], [], [], [], [], [1"
89-- Iteration 17 --
90string(11) "4], [5], [6"
91-- Iteration 18 --
92string(13) "10], [20], [3"
93Done
94