Re: Storing an array on a table?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



if you just have a simple array with automatic numeric keys and text you could just implode the data to a string with a separator not found in your data:
$dataArray = array("hello", "goodbye", "etc.");
$storable = implode("||||", $dataArray);
// $storable becomes "hello||||goodbye||||etc."

//then, use explode to get the original array back again
$dataArray = explode("||||", $storable);

you could use a similar technique if you want to put the keys in as well, albeit slightly more complicated (e.g. use "||||" to separate each element in the array and "||" to separate each key from its value). Just find a divider you know your data will not contain, such as a pipe: "|".

This has worked well for me.

Jordan



On Sep 1, 2005, at 8:55 AM, Miguel Guirao wrote:



I want to store an array into a field on a MySQL table, Is it posible to
save it? Maybe into a string field?



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux