Re: How to convert array to string, and vice versa



In article <xvHcg.10455$S.4851@xxxxxxxxxxxxxxxxxxxx>,
Oli Filth <catch@xxxxxxxxxxxxxx> wrote:

Tim Streater said the following on 23/05/2006 17:49:
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.


Is it absolutely mandatory that you put these into a single record?
This is almost certainly a bad idea. Not only do you have to write
conversion functions to get data into and out of the database, but you
data is no longer atomic. Amongst other things, this makes it difficult
to search, index, delete or reference your data...

Oli,

Thanks for pushing me to re-think my strategy. Choosing a good data
representation is most of the battle and while driving home and back to
work this morning [1] I had a think about better ways to represent the
data which would retain the flexibility while not burdening the general
and presentation suite. Generally I don't like hacks anyway as they tend
to come back to bite you.

Thanks to the other responders - there are many functions in PHP I am
not familiar with so being pointed at some new ones for a specific
purpose will be a good exercise.

[1] Radio 4 only had an unfunny comedy program last night and a poor
magazine program this morning, as it happened, so I turned the radio off
while driving.

Cheers,

-- 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: 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
    ... Tim Streater said the following on 23/05/2006 17:49: ... All these items need to be represented in a single already existing database record. ... and converting it to a single string: ... Not only do you have to write conversion functions to get data into and out of the database, but you data is no longer atomic. ...
    (comp.lang.php)
  • Re: How to convert array to string, and vice versa
    ... Tim Streater wrote: ... All these items need to be represented in a single already existing database record. ... and converting it to a single string: ... I can't see any array or string function that looks designed for this or a similar purpose. ...
    (comp.lang.php)
  • Re: Unicode question
    ... Obviously not for the representation in memory;-) ... They fit your approach to string handling. ... character encoding, or in the average or precise display width of the ... Since UTF-16 chars can be 2 or 4 bytes, one has to be always alert ...
    (borland.public.delphi.non-technical)