Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "id": "8488",
- "name": "Tenby",
- "area": "Area1"
- },
- {
- "id": "8489",
- "name": "Harbour",
- "area": "Area1"
- },
- {
- "id": "8490",
- "name": "Mobius",
- "area": "Area1"
- }
- ]
- [
- {
- "id": "8488",
- "name": "Tenby",
- "area": "Area1",
- "image": "1278.jpg"
- },
- {
- "id": "8489",
- "name": "Harbour",
- "area": "Area1",
- "image": "1279.jpg"
- },
- {
- "id": "8490",
- "name": "Mobius",
- "area": "Area1",
- "image": "1280.jpg"
- }
- ]
- <?php
- $data[0]['id']="8488";
- $data[0]['name']="Tenby";
- $data[0]['area']="Area1";
- $data[1]['id']="8489";
- $data[1]['name']="Harbour";
- $data[1]['area']="Area1";
- $data[2]['id']="8490";
- $data[2]['name']="Mobius";
- $data[2]['area']="Area1";
- echo json_encode($data)."<br/>";
- /*Add Image element (or whatever) into the array according to your needs*/
- $data[0]['image']="1278.jpg";
- $data[1]['image']="1279.jpg";
- $data[2]['image']="1280.jpg";
- echo json_encode($data);
- ?>
- $temp = json_decode($json);
- $temp[] = new data, whatever you want to add...;
- $json = json_encode($temp);
- $strJSON = '[
- {
- "id": "8488",
- "name": "Tenby",
- "area": "Area1"
- },
- {
- "id": "8489",
- "name": "Harbour",
- "area": "Area1"
- },
- {
- "id": "8490",
- "name": "Mobius",
- "area": "Area1"
- }
- ]';
- $json = json_decode( $strJSON );
- $json[0]->image = "1278.jpg";
- $json[1]->image = "1279.jpg";
- $json[2]->image = "1280.jpg";
- echo "<pre>";
- print_r( $json );
- echo "</pre>";
- Array
- (
- [0] => stdClass Object
- (
- [id] => 8488
- [name] => Tenby
- [area] => Area1
- [image] => 1278.jpg
- )
- [1] => stdClass Object
- (
- [id] => 8489
- [name] => Harbour
- [area] => Area1
- [image] => 1279.jpg
- )
- [2] => stdClass Object
- (
- [id] => 8490
- [name] => Mobius
- [area] => Area1
- [image] => 1280.jpg
- )
- )
Add Comment
Please, Sign In to add comment