我有serialized array
如下:
a:22:{s:18:"'myprofiledefault'";s:1:"2";s:19:"'myprofilepersonal'";s:1:"0";s:14:"'myprofilejob'";s:1:"0";s:16:"'myprofileleave'";s:1:"0";s:21:"'myprofilepermission'";s:1:"0";s:28:"'myprofilebonus & commision'";s:1:"0";s:19:"'myprofiledocument'";s:1:"0";s:28:"'myprofileemergency contact'";s:1:"0";s:19:"'myprofilebenifits'";s:1:"0";s:17:"'view empdefault'";s:1:"0";s:18:"'view emppersonal'";s:1:"0";s:13:"'view empjob'";s:1:"0";s:15:"'view empleave'";s:1:"0";s:20:"'view emppermission'";s:1:"0";s:27:"'view empbonus & commision'";s:1:"0";s:18:"'view empdocument'";s:1:"0";s:27:"'view empemergency contact'";s:1:"0";s:18:"'view empbenifits'";s:1:"0";s:15:"'view empnotes'";s:1:"0";s:17:"'view emponboard'";s:1:"0";s:18:"'view empoffboard'";s:1:"0";s:16:"'view empcharts'";s:1:"0";}
如果我unserialized
这和打印意味着它将如下所示:
Array(['myprofiledefault'] => 2
['myprofilepersonal'] => 0
['myprofilejob'] => 0
['myprofileleave'] => 0
['myprofilepermission'] => 0
['myprofilebonus & commision'] => 0
['myprofiledocument'] => 0
['myprofileemergency contact'] => 0
['myprofilebenifits'] => 0
['view empdefault'] => 0
['view emppersonal'] => 0
['view empjob'] => 0
['view empleave'] => 0
['view emppermission'] => 0
['view empbonus & commision'] => 0
['view empdocument'] => 0
['view empemergency contact'] => 0
['view empbenifits'] => 0
['view empnotes'] => 0
['view emponboard'] => 0
['view empoffboard'] => 0
['view empcharts'] => 0)
我的问题是我想单独获取关键值。
我正在尝试这个
echo $ret['myprofilepersonal'];
但这不起作用,显示错误未定义的索引。请问如何获得
答案 0 :(得分:4)
如果我们假设你反序列化你发布的数组,那么:
$ret = unserialize(...);
然后你需要使用sth访问这些值:
echo $ret["'myprofiledefault'"];
// or by escaping single quote:
echo $ret['\'myprofiledefault\''];
因为我看到,每个键都被引用