Guest User

Untitled

a guest
Oct 17th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. [
  2. {
  3. "id": "8488",
  4. "name": "Tenby",
  5. "area": "Area1"
  6. },
  7. {
  8. "id": "8489",
  9. "name": "Harbour",
  10. "area": "Area1"
  11. },
  12. {
  13. "id": "8490",
  14. "name": "Mobius",
  15. "area": "Area1"
  16. }
  17. ]
  18.  
  19. [
  20. {
  21. "id": "8488",
  22. "name": "Tenby",
  23. "area": "Area1",
  24. "image": "1278.jpg"
  25. },
  26. {
  27. "id": "8489",
  28. "name": "Harbour",
  29. "area": "Area1",
  30. "image": "1279.jpg"
  31. },
  32. {
  33. "id": "8490",
  34. "name": "Mobius",
  35. "area": "Area1",
  36. "image": "1280.jpg"
  37. }
  38. ]
  39.  
  40. <?php
  41.  
  42. $data[0]['id']="8488";
  43. $data[0]['name']="Tenby";
  44. $data[0]['area']="Area1";
  45.  
  46. $data[1]['id']="8489";
  47. $data[1]['name']="Harbour";
  48. $data[1]['area']="Area1";
  49.  
  50. $data[2]['id']="8490";
  51. $data[2]['name']="Mobius";
  52. $data[2]['area']="Area1";
  53.  
  54. echo json_encode($data)."<br/>";
  55.  
  56. /*Add Image element (or whatever) into the array according to your needs*/
  57.  
  58. $data[0]['image']="1278.jpg";
  59. $data[1]['image']="1279.jpg";
  60. $data[2]['image']="1280.jpg";
  61.  
  62. echo json_encode($data);
  63.  
  64. ?>
  65.  
  66. $temp = json_decode($json);
  67. $temp[] = new data, whatever you want to add...;
  68. $json = json_encode($temp);
  69.  
  70. $strJSON = '[
  71. {
  72. "id": "8488",
  73. "name": "Tenby",
  74. "area": "Area1"
  75. },
  76. {
  77. "id": "8489",
  78. "name": "Harbour",
  79. "area": "Area1"
  80. },
  81. {
  82. "id": "8490",
  83. "name": "Mobius",
  84. "area": "Area1"
  85. }
  86. ]';
  87.  
  88. $json = json_decode( $strJSON );
  89.  
  90. $json[0]->image = "1278.jpg";
  91. $json[1]->image = "1279.jpg";
  92. $json[2]->image = "1280.jpg";
  93.  
  94. echo "<pre>";
  95. print_r( $json );
  96. echo "</pre>";
  97.  
  98. Array
  99. (
  100. [0] => stdClass Object
  101. (
  102. [id] => 8488
  103. [name] => Tenby
  104. [area] => Area1
  105. [image] => 1278.jpg
  106. )
  107.  
  108. [1] => stdClass Object
  109. (
  110. [id] => 8489
  111. [name] => Harbour
  112. [area] => Area1
  113. [image] => 1279.jpg
  114. )
  115.  
  116. [2] => stdClass Object
  117. (
  118. [id] => 8490
  119. [name] => Mobius
  120. [area] => Area1
  121. [image] => 1280.jpg
  122. )
  123.  
  124. )
Add Comment
Please, Sign In to add comment