Hi All,

I have a number of arrays stored as a text string in a database (ive included it at the very bottom).

As this is a text string i need to know how to convert it back into an array.

Also, how can i access a single element, i.e first name?

Do i need to split the whole thing down and build my array?

bear in mind that below isnt an array, its just a long string

Array
(
[firstname] => thefirstname
[lastname] => thelastname
[email] => the email
[gender] => Male
[dob] => Array
(
[day] => 16
[month] => 3
[year] => 1978
)

[interested] => Array
(
[bread] => 1
[milk] => 1
)

[agree] => 1
[x] => 53
[y] => 15
)

If you want to store an object or array in a textual format, you should serialize it before storing and unserialize it to reverse the process.

It looks like what you have is an exported array. I'm not aware of a way to import an array in that format, but then I've never looked.

R.

<?php
$string = "Array(
  [firstname] => thefirstname
  [lastname] => thelastname
  [email] => the email
  [gender] => Male
  [dob] => Array
  (
  [day] => 16
  [month] => 3
  [year] => 1978
  )

  [interested] => Array
  (
  [bread] => 1
  [milk] => 1
  )

  [agree] => 1
  [x] => 53
  [y] => 15
  )";
$array = eval($string);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.