How to convert array to string, and vice versa



I have some items, numbered from 0 upwards. Some of them may have a
string attached. All these items need to be represented in a single
already existing database record. So, I thought of taking an array, as
it might be looking thus (the values are all strings):

Key Value
--- -----
0 firstone
2 somestring
5 anotherstr


and so on, and converting it to a single string:

"'0', 'firstone', '2', 'somestring', '5', 'anotherstr'"

then I have a string I can write to the database record.

So I want to go from:

$myarr = array (0 => 'firstone', 2 => 'somestring', 5 => 'anotherstr');

to:

$mystring = "'0', 'firstone', '2', 'somestring', '5', 'anotherstr'";

Is there a quick way to do this mapping in both directions? (I don't
mind if the string read/written to the database is not as above, as it
won't be used for any other purpose).

I can't see any array or string function that looks designed for this or
a similar purpose.

Thanks for any pointers.

-- tim
.



Relevant Pages

  • Re: How to convert array to string, and vice versa
    ... and converting it to a single string: ... then I have a string I can write to the database record. ... information about the port optics. ... to have a set of port-records, pointing to the interface card. ...
    (comp.lang.php)
  • Re: How to convert array to string, and vice versa
    ... and converting it to a single string: ... then I have a string I can write to the database record. ... representation is most of the battle and while driving home and back to ... Radio 4 only had an unfunny comedy program last night and a poor ...
    (comp.lang.php)
  • Function problem
    ... having programmed VB6 and VB.NET for some time. ... The purpose is to pass in a string, and return a long (would prefer ... it's own array member in the outgoing array in ASCII equivs. ...
    (microsoft.public.vc.language)
  • Re: DBI update
    ... > In the following snippet of code, I'm trying to update several fields in a ... > $set, in the prepare statement, is a string that contains field/value pairs ... and save your values in an array rather than a skalar. ...
    (comp.lang.perl.misc)
  • Re: How to convert array to string, and vice versa
    ... So, I thought of taking an array, as ... and converting it to a single string: ... then I have a string I can write to the database record. ...
    (comp.lang.php)