Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change just 1 key in a serialised array with 3 keys using php function

I am trying to import values which are stored as a serialised array with 3 keys like this:

a:3:{i:754;s:0:"";i:753;s:0:"";i:752;s:0:"";}

Would anyone know a php function to change the value within 1 key (adjust 754) and leave the other keys as they were?

I’m using WP ALL Import and i can match my records and adjust the value for 754, but it changes the entire serialised array, deleting the other values in the other 2 keys

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you in advance

>Solution :

This would replace the value of array Occurance 754

$serial = 'a:3:{i:754;s:0:"";i:753;s:0:"";i:752;s:0:"";}';

$arr = unserialize($serial);

$arr[754] = 'NEW';
print_r($arr);
echo $serial = serialize($arr);

RESULT

Array
(
    [754] => NEW
    [753] => 
    [752] => 
)
a:3:{i:754;s:3:"NEW";i:753;s:0:"";i:752;s:0:"";}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading