2

Lets say I have this data...just an example!

    Before Serialize
        array (size=2)
          'first_name' => string 'Swashata'
          'last_name' => string 'Ghosh'
    After Serialize
   a:2:{s:10:"first_name";s:8:"Swashata";s:9:"last_name";s:5:"Ghosh";}

So after the serialized data I'm going to unserialized it and get each value of the element of array to make it variable. The problem here is I want to get each element to make them a variable so that I can easily call them when I need it. Thanks! ahead.

cachess
  • 163
  • 1
  • 5
  • 18

3 Answers3

1

I think you ask for extraction of key => value to variables..

So ..

$array = array(
    'first_name' => 'Swashata'
    'last_name' => 'Ghosh'
);

extract($array);

This will create variables called $first_name and $last_name with their values from your array..

Svetoslav
  • 4,686
  • 2
  • 28
  • 43
1

After unserialize you need to call

$unserialized = unserialize($data);
echo $unserialized['last_name'];

not $unserialized[0]

You can use this as well

extract($unserialized);
echo $last_name;

Hope this is helpful.

0

Its in json format

Use json_decode() to get the values from serialized data

$a = "serialized data";
$arr = json_decode($a);
print_r($arr);// will get back the result
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41