Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:13:44+00:00 2026-06-17T12:13:44+00:00

[ { id : 1, name : levin, description : some desc, size :

  • 0
[
  {
     "id"  : 1,
    "name"  : "levin",
    "description" : "some desc",
    "size"  : "100KG",
     "actions" : {
                 "walking" : true,
                  "eating" : true
                  }
  },
  {
    "id"  : 2,
    "name"  : "clara",
    "description" : "some desc",
    "size"  : "2000KG",
     "actions" : {
                 "walking" : false,
                  "eating" : true
                  }

  }
]

This is my person.json file. I like to update(overwrite) existing values. Am not found any useful questions regarding this.

i have a name “levin” i like to overwrite it to empty or “—“. But its should only based through “id” .Following is my php code but its not working 🙁

public function api_put()
    {
         //print($this->put('id')); am getting here 2 value from other page 
        //print($this->put('action'));.

        if($this->put('action') == "remove"){
            $file = json_decode(file_get_contents("assets/json/person.json"));
            $new_val = array();
            $i = 0 ;
            foreach ($file as $key => $value) {
                if((string)$value->id == $this->put('id')) {
                    $data[] = (string)$value->name="--";(string)$value->description="--";
                    $new_val[$i] =  $data;
                    $i++;
                }

            }
            file_put_contents('assets/json/person.json', json_encode($new_val));
            $message = array('id' => $this->put('id'), 'message' => 'Successfully updated!!');

            $this->response($message, 200); 
        }
    }

How can i overwrite a json value depend upon a particular id and with out change all other id data. am using codeigniter REST api. thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:13:46+00:00Added an answer on June 17, 2026 at 12:13 pm

    I think you must need to loop like this to store all details

    foreach ($file as $key => $value) {
        if((string)$value->id == $this->put('id')) {
            $value->name="--";(string)$value->description="--";
        }
            $new_val[$i] =  $value;
        $i++;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[{name:Mark,Surname:Gaux}] [{Job:2,Type:Office}] I have this JSON echoed by a PHP file on the server
name 'entry_resource' is not defined This is my models.py from tastypie.utils.timezone import now from
name = MagApp 1.0 description = Magapp module that enables MagApp powered publications. core
I've try to make some code, but I found some problem... This is my
Name: <%= Html.TextBox(txtName, 20, new { @class = hello }) %> I want that
id name mydate 1 co 2011-02-10 07:25:02 2 Carl 2011-02-10 07:26:02 . . .
The name says it all really. I suspect that insertion sort is best, since
string name = bob; object obj = name; obj = joe; Console.WriteLine(name); I'm a
database name customdata jobNo CustomerName Country Tel Item 1 John USA 045 Mouse 2
Which name need the sql-file in the sql folder? When I want to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.