blob: 937f79ac72bddefe5d4572ada8672588186f5d63 (
plain)
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
|
/**
*
* Test variables
* 008-value-arrays.phpt
*
*/
namespace TestVariables {
/*
* Test Php::Value arrays
*/
Php::Value value_arrays(void)
{
// create a regular array
Php::Value array;
array[0] = "apple";
array[1] = "banana";
array[2] = "tomato";
// an initializer list can be used to create a filled array
Php::Value filled({ "a", "b", "c", "d"});
// create an associative array
Php::Value assoc;
assoc["apple"] = "green";
assoc["banana"] = "yellow";
assoc["tomato"] = "green";
// the variables in an array do not all have to be of the same type
Php::Value assoc2;
assoc2["x"] = "info@example.com";
assoc2["y"] = nullptr;
assoc2["z"] = 123;
// nested arrays are possible too
Php::Value assoc3;
assoc3["x"] = "info@example.com";
assoc3["y"] = nullptr;
assoc3["z"][0] = "a";
assoc3["z"][1] = "b";
assoc3["z"][2] = "c";
Php::Value r;
r["array"] = array;
r["filled"] = filled;
r["assoc"] = assoc;
r["assoc2"] = assoc2;
r["assoc3"] = assoc3;
return r;
}
}
|