3

我有一个数组,其中所有键值都以序列化方式这里是示例代码

Array
(
    [Entry1] => Array
    (
        [emergency_contact] => s:205:"a:5:{s:22:"emergency_contact_name";s:0:"";s:23:"emergency_contact_email";s:0:"";s:23:"emergency_contact_phone";s:0:"";s:26:"emergency_contact_relation";s:0:"";s:30:"emergency_contact_rx_allergies";s:0:"";}";
        [email] => s:23:"h.v@gmail.com";
        [c_address] => s:14:"1067 Broad Way";
        [c_address2] => s:6:"Mangal";
        [c_postcode] => s:5:"12345";
        [c_city] => s:14:"Sans Frnasisco";
        [c_state] => s:7:"LOS";
        [c_country_of_residence] => s:3:"109";
    )
    [Entry2] => Array
    (
        [emergency_contact] => s:205:"a:5:{s:22:"emergency_contact_name";s:0:"";s:23:"emergency_contact_email";s:0:"";s:23:"emergency_contact_phone";s:0:"";s:26:"emergency_contact_relation";s:0:"";s:30:"emergency_contact_rx_allergies";s:0:"";}";
        [email] => s:23:"h.v@gmail.com";
        [c_address] => s:14:"1067 Broad Way";
        [c_address2] => s:6:"Mangal";
        [c_postcode] => s:5:"12345";
        [c_city] => s:14:"Sans Frnasisco";
        [c_state] => s:7:"LOS";
        [c_country_of_residence] => s:3:"109";
    )
)

有什么办法可以查看所有数据更改它并以相同的方式再次序列化它?谢谢。

4

1 回答 1

1
array_walk_recursive($array, function (&$value) { $value = unserialize($value); });

// do something with the array

array_walk_recursive($array, function (&$value) { $value = serialize($value); });

但实际上,将每个单独的值序列化是相当疯狂的。如果可以的话,你应该停止它。

于 2013-03-06T07:28:46.890 回答