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 9159359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:28:23+00:00 2026-06-17T13:28:23+00:00

I need some help with unserializing and updating the array values and reserializing them

  • 0

I need some help with unserializing and updating the array values and reserializing them (using php). Basically I want to be able to unserialize a string, update the value for a specific key (without loosing the other values) and reserialize it. I’ve searched and can’t seem to find a viable solution (or maybe I’m just typhlotic).

The array I’m trying to update is very simple. It has a key and value.

array (
    'key' => 'value',
    'key2' => 'value2',
)

I currently have, but it does not work.

foreach(unserialize($serializedData) as $key => $val)
{
    if($key == 'key')
    {
        $serializedData[$key] = 'newValue';
    }
}

$updated_status = serialize($serializedData);
  • 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-17T13:28:25+00:00Added an answer on June 17, 2026 at 1:28 pm

    You can’t write directly to the serialized data string like you are trying to do here:

    $serializedData[$key] = 'newValue';
    

    You need to deserialize the data to an array, update the array, and then serialize it again. It seems as if you only want to update the value if the key exists, so you can do it like this:

    $data = unserialize($serializedData);
    if(array_key_exists('key', $data)) {
        $data['key'] = 'New Value';
    }
    $serializedData = serialize($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need some help regarding adding values into an array for example long[] s
need some help with retrieving information+Profile pic from twitter using php , i wanted
Need some help with a Magento php script.... I want do write an if
Need some help with crypto routines in Java. Given a PKCS#7 signature, I want
Need some help: I want to only pull back the results for a specific
Need some help finishing up this program, everything works and runs like I want
Need some help with putting this query together. I'm using Mysql I have two
I need some help about PHP GD. Here is my piece of code. header(Content-type:
I need some help with allocating arrays dynamically. I have an array whose size
I need some help. Basically, I have a large dataset that I have split

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.