Search
 
SCRIPT & CODE EXAMPLE
 

PHP

update json file php

First, you need to decode it :

$jsonString = file_get_contents('jsonFile.json');
$data = json_decode($jsonString, true);
Then change the data :

$data[0]['activity_name'] = "TENNIS";
// or if you want to change all entries with activity_code "1"
foreach ($data as $key => $entry) {
    if ($entry['activity_code'] == '1') {
        $data[$key]['activity_name'] = "TENNIS";
    }
}
Then re-encode it and save it back in the file:

$newJsonString = json_encode($data);
file_put_contents('jsonFile.json', $newJsonString);
Comment

php update json file

$newJsonString = json_encode($data);
file_put_contents('jsonFile.json', $newJsonString);
Comment

php update json file

$jsonString = file_get_contents('jsonFile.json');
$data = json_decode($jsonString, true);
Comment

php update json file

$data[0]['activity_name'] = "TENNIS";
// or if you want to change all entries with activity_code "1"
foreach ($data as $key => $entry) {
    if ($entry['activity_code'] == '1') {
        $data[$key]['activity_name'] = "TENNIS";
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: list database table rows plugin wordpress 
Php :: query for current editing post id 
Php :: ipv6 pregmatch 
Php :: livewire component lost data 
Php :: how to print image just on side where upload php 
Php :: Grab files matching particular file types in a directory 
Php :: How can I share limits across multiple fields gravity forms? 
Php :: word limit in php 
Php :: how to compare two strings ignoring accentuation in php 
Php :: dump request in ci 
Php :: laravel livewire refresh computed property 
Php :: flexslider in laravel 5.8 
Php :: ftp is uploading file but 0kb file size or data 
Php :: fxcjahid 
Php :: Argument #1 ($baseObject) must be of type DateTimeInterface, string given 
Php :: chart trong laravel 
Php :: php get cosine sim 
Php :: php kurzschreibweise if 
Php :: loop IlluminateSupportCollection Object ( [items:protected] = 
Php :: laravel retain old value 
Php :: how to keep some value on input field 
Php :: Hide products only show assigned products to certain user roles in WooCommerce 
Php :: php hook function 
Php :: es php query where value is not empty 
Php :: php getgmail name 
Php :: symfony 6 download 64 bit 
Php :: how to get data from laravel api 
Php :: php string filter email 
Php :: laravel collection unique 
Php :: laravel validation alphanumeric with spaces 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =