File: array_merge_recursive_variation9.phpt

package info (click to toggle)
php5 5.6.33%2Bdfsg-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 157,872 kB
  • sloc: ansic: 756,065; php: 22,030; sh: 12,311; cpp: 8,771; xml: 6,179; yacc: 1,564; exp: 1,514; makefile: 1,467; pascal: 1,147; awk: 538; perl: 315; sql: 22
file content (117 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--TEST--
Test array_merge_recursive() function : usage variations - common key and value(Bug#43559)
--FILE--
<?php
/* Prototype  : array array_merge_recursive(array $arr1[, array $...])
 * Description: Recursively merges elements from passed arrays into one array
 * Source code: ext/standard/array.c
*/

/*
 * Testing the functionality of array_merge_recursive() by passing 
 * arrays having common key and value.
*/

echo "*** Testing array_merge_recursive() : arrays with common key and value ***\n";

/* initialize the array having duplicate values */

// integer values
$arr1 = array("a" => 1, "b" => 2);
$arr2 = array("b" => 2, "c" => 4);
echo "-- Integer values --\n";
var_dump( array_merge_recursive($arr1, $arr2) );

// float values
$arr1 = array("a" => 1.1, "b" => 2.2);
$arr2 = array("b" => 2.2, "c" => 3.3);
echo "-- Float values --\n";
var_dump( array_merge_recursive($arr1, $arr2) );

// string values
$arr1 = array("a" => "hello", "b" => "world");
$arr2 = array("b" => "world", "c" => "string");
echo "-- String values --\n";
var_dump( array_merge_recursive($arr1, $arr2) );

// boolean values
$arr1 = array("a" => true, "b" => false);
$arr2 = array("b" => false);
echo "-- Boolean values --\n";
var_dump( array_merge_recursive($arr1, $arr2) );

// null values
$arr1 = array( "a" => NULL);
$arr2 = array( "a" => NULL);
echo "-- Null values --\n";
var_dump( array_merge_recursive($arr1, $arr2) );

echo "Done";
?>
--EXPECTF--
*** Testing array_merge_recursive() : arrays with common key and value ***
-- Integer values --
array(3) {
  ["a"]=>
  int(1)
  ["b"]=>
  array(2) {
    [0]=>
    int(2)
    [1]=>
    int(2)
  }
  ["c"]=>
  int(4)
}
-- Float values --
array(3) {
  ["a"]=>
  float(1.1)
  ["b"]=>
  array(2) {
    [0]=>
    float(2.2)
    [1]=>
    float(2.2)
  }
  ["c"]=>
  float(3.3)
}
-- String values --
array(3) {
  ["a"]=>
  string(5) "hello"
  ["b"]=>
  array(2) {
    [0]=>
    string(5) "world"
    [1]=>
    string(5) "world"
  }
  ["c"]=>
  string(6) "string"
}
-- Boolean values --
array(2) {
  ["a"]=>
  bool(true)
  ["b"]=>
  array(2) {
    [0]=>
    bool(false)
    [1]=>
    bool(false)
  }
}
-- Null values --
array(1) {
  ["a"]=>
  array(2) {
    [0]=>
    NULL
    [1]=>
    NULL
  }
}
Done