“Tambahkan data ke file JSON PHP” Kode Jawaban

Tambahkan ke JSON Object PHP

<?php
$arr = '[
   {
      "id":1,
      "name":"Charlie"
   },
   {
      "id":2,
      "name":"Brown"
   },
   {
      "id":3,
      "name":"Subitem",
      "children":[
         {
            "id":4,
            "name":"Alfa"
         },
         {
            "id":5,
            "name":"Bravo"
         }
      ]
   },
   {
      "id":8,
      "name":"James"
   }
]';
$arr = json_decode($arr, TRUE);
$arr[] = ['id' => '9999', 'name' => 'Name'];
$json = json_encode($arr);

echo '<pre>';
print_r($json);
echo '</pre>';
Strange Salamander

file_put_contents php json file

$data[] = $_POST['data'];

$inp = file_get_contents('results.json');
$tempArray = json_decode($inp);
array_push($tempArray, $data);
$jsonData = json_encode($tempArray);
file_put_contents('results.json', $jsonData);
Waved Albatross

Tambahkan data ke file JSON PHP

test1rwww33rwrw
Comfortable Capybara

PHP JSON Array Push dalam file JS

{"Markers": [
{
  "title" : "Meow Monestary",
  "position" : {
    "lat" : 40.5178,
    "lng" : -122.6438
  },
  "posterContact" : {
    "name" : "Mr Meowser",
    "email" : "[email protected]",
    "phone" : "(555)-202-3040",
    "private" : true
  },
  "type" : "myResidence",
  "ownerContact" : {
    "name" : false,
    "email" : false,
    "phone" : false,
    "private" : true
  },
  "description" : "Meow meow purrrrr.  Dogs are not my favorite but they are my second favorite.",
  "private" : true
},
Joyous Jay

Jawaban yang mirip dengan “Tambahkan data ke file JSON PHP”

Pertanyaan yang mirip dengan “Tambahkan data ke file JSON PHP”

Lebih banyak jawaban terkait untuk “Tambahkan data ke file JSON PHP” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya