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 :: get table name of model laravel 
Php :: wp display custom fields 
Php :: post json php 
Php :: convert json object to array in php 
Php :: form submitting twice 
Php :: redirect from controller in laravel 
Php :: how to get value of textarea in php 
Php :: laravel inverse seeder 
Php :: php is scan dir recursive? 
Php :: convert string to datetime symfony 
Php :: PHP Deprecated: Function create_function() 
Php :: how to create compomemt in laravel livewire 
Php :: csv to array in php 
Php :: php mail success message 
Php :: laravel check pagination in blade 
Php :: order number generate laravel 
Php :: php pass by reference 
Php :: php function exists 
Php :: confirm password validation in laravel 
Php :: how run phpunit test repeat 
Php :: foreign key in laravel 
Php :: remove first element in array php 
Php :: carbon random future date 
Php :: General error: 1709 Index column size too large. The maximum column size is 767 bytes. 
Php :: php pdo select 
Php :: route params link laravel 
Php :: loop object property laravel 
Php :: laravel string capitalize in view 
Php :: laravel storage get file path 
Php :: laravel blade dump 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =