/
JengineSample.php
63 lines (39 loc) · 1.42 KB
/
JengineSample.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
<?php
/**
* Created by PhpStorm.
* User: davcharles
* Date: 18/01/2016
* Time: 01:22 PM
*/
require_once('Jengine.php');
echo "<b> Creating a new json template using attributes</b>";echo '</br></br>';
$json_attributes = array("color", "speed", "type");//attributes of a car object
$template=Jengine::json_template($json_attributes);
echo $template;
//Result:
/*
[{
"color": "*empty*",
"speed": "*empty*",
"type": "*empty*"
}]
*/
echo '</br></br></br>';
echo "<b> Adding data to the new Template</b>";echo '</br></br>';
$json_data1=array("red", "slow", "volvo");
$json_data2=array("Green", "fast", "viper");
$template=Jengine::json_add($template,$json_data1);
echo $template;
//Result:
//[{"color":"red","speed":"slow","type":"volvo"}]
echo '</br></br>';
$template=Jengine::json_add($template,$json_data2);
echo $template;
echo '</br></br></br>';
//Result:
//[{"color":"red","speed":"slow","type":"volvo"},{"color":"Green","speed":"fast","type":"viper"}]
echo "<b> Using template loaded from data source</b>";echo '</br></br>';
echo '</br></br>';
$template=Jengine::json_template('http://localhost/PHP-JSONengine/data.json');
echo $template;
//[{ "Name": "David Charles", "City": "Berlin", "Country": "Germany" }, { "Name": "Ana Trujillo Emparedados y helados", "City": "México D.F.", "Country": "Mexico" }, { "Name": "Antonio Moreno TaquerÃa", "City": "México D.F.", "Country": "Mexico" }]