Using explode function with a variable in the string?
php
Solution
Don't do it this way. if you need to serialize a string use json_encode():
$string = json_encode($data);
Then, when you need to decode it again:
$data = json_decode($string);
Safe and easy.
Here's the PHP reference: json_encode()
Problem
I have an array with $post_id as keys. When save the $data, I saved it as a string: ``` foreach( $data as $post_id => $details ) $string .= "-pid-$post_id-$details"; ``` When use the data, I need to convert it back to array with $post_id as key and $details as value. How to explode it when I don't know what is the $post_id ?