这是存储在MySQL数据库中的序列化数据:
sizes_0#10_1$shape_0#20$bannertype_0#20$sizes_1#1_3$shape_1#20$
如何从上述数据中删除sizes1
?
答案 0 :(得分:0)
首先,您应该反序列化数据:
$string = 'sizes_0#10_1$shape_0#20$bannertype_0#20$sizes_1#1_3$shape_1#20$';
function custom_unserialize($string) {
return array_map(function($token) {
return explode('#', $token);
}, explode('$', $string));
}
$data = custom_unserialize($string);
然后您可以删除sizes1
条目:
$data_without_sizes_1 = array_filter($data, function($data) {
return $data[0] !== 'sizes_1';
});
最后你可以再次序列化数据:
function custom_serialize(array $data) {
return implode('$', array_map(function($entry) {
return implode('#', $entry);
}, $data));
}
$serialized_string = custom_serialize($data_without_sizes_1);