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