0

I have an serialized array like below:

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";}

If i unserialized this and print means it will be look like below:

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)

My question is that i want to get the key values individually.

I am trying this one

echo $ret['myprofilepersonal'];

but this is not working showing an error undefined index. Please How to get this

3
  • Show all the relevant code. This should be pretty simple. Commented Oct 27, 2015 at 9:31
  • do a var_dump on your $ret. and post the output here Commented Oct 27, 2015 at 9:34
  • Maybe $ret[0]['myprofilepersonal'] Commented Oct 27, 2015 at 9:39

1 Answer 1

4

If we suppose that you unserialize the array you posted like so:

$ret = unserialize(...);

Then you need to access the values using sth like this:

echo $ret["'myprofiledefault'"];
// or by escaping single quote:
echo $ret['\'myprofiledefault\''];

because as I see, every key is quoted

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.