0

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
)
3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by NettSite
0

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.

0
<?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);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.