Unserialize data

I am pulling some data from a table that look like this:

a:2:{i:10;a:2:{s:8:“shipping”;s:28:“STANDARD 5 - 7 Business Days”;s:5:“rates”;a:1:{i:40;d:4.75;}}i:26;a:2:{s:8:“shipping”;s:13:"Anxiety Wrap ";s:5:“rates”;a:1:{i:20;d:6.75;}}}

I want to have a function that will return me an array with just the 2 pieces of informaiton I need from this string… in this case the 2 shipping rates after the d: - so 4.75 and 6.75

Any ideas?

Thanks in advance.

Why are you storing it in your table as serialized data in the first place? Database tables are made for making dedicated storage elements for every piece of information you’d want stored in a relational way. Why abuse that concept by serializing an object, compromising the human-readable argument, and throwing it into a single database field?

I understand the need of serializing data. We have to serialize a lot of data at my work.

You can unserialize the string from the table using the unserialize() function, which returns your array of data. From there, you’ll need to iterate down to your information.

Serializing of data is done with a purpose, and that purpose can clearly not be storing said data in a database. If there is any reason I’ve overlooked on why serialized data in a relational database is preferrable over the conventional method, please point it out to me.

When licensing compiled PHP software and you want to keep data convoluted. We serialize data at work for our online assessment utility.

I still fail to see the necessity for serialization of data before storage in a relational database. If the overhead can be recreated regardless of the actual data that you want stored, then why serialize? Serializing is used for, for example, transferring a live object through a socket. Even sessions get unraveled before their information gets stored in my applications.

Sponsor our Newsletter | Privacy Policy | Terms of Service