-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
69 lines (53 loc) · 1.54 KB
/
example.php
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
<?php
/* Create new tree */
$db = new Atree;
/* Car object */
class Car {
private $make;
private $age;
function __construct($make, $age) {
$this->make = $make;
$this->age = $age;
}
function toString() {
return "Car " . $this->make . " is " . $this->age . " years old";
}
}
/* Create instances */
$chevy = new Car("Chevy", 2);
$ford = new Car("Ford", 5);
/* Insert objects */
$db->put("car.garage.chevy", $chevy);
$db->put("car.garage.ford", $ford);
/* Insert other types in the same prefix */
$db->put("car.all_ensured", true);
$db->put("car.fuelprice", array('disel' => 1, 'gas' => 4));
/* Other types */
$db->put("myname", "John Doe");
$db->put("list::Jane", "Smith");
$db->put("list::Hank", "Johnson");
$db->put("list::Joe", "Williams");
$db->put("list::Dave", "Jones");
$db->put("list::Mary", "James");
$db->put("list::John", "Davids");
$db->put("list::Thomas", "Phillips");
$db->put("list::Sofia", "Ángel");
/* Current tree size */
echo "Elements in tree " . $db->size() . "\n";
/* Echo myname */
echo "Hello, " . $db->get("myname") . "\n";
/* Show cars in garage */
foreach($db->prefix("car.garage") as $car) {
echo $car->toString() . "\n";
}
/* Delete an user */
$db->delete("list::Mary");
/* Show users beginning with an 'J' */
foreach($db->prefix("list::J") as $user => $name) {
echo "User " . explode("::", $user)[1] . " " . $name . " is active\n";
}
/* And wer're done with this tree */
$db->clear();
$db->put("php version", array(5, 7));
$db->put("license", "PHP");
print_r($db->all());