Array value concatenation?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dillion
Forum Commoner
Posts: 56
Joined: Thu Feb 15, 2007 8:32 am

Array value concatenation?

Post by dillion »

A client uses a custom-built software that manages their products catalog and this software generates a flat file which I can use to populate mySQL database for the online shop. Simple example of the flatfile:

Code: Select all

 
Title|iPod
Price|200
Stock|10
 
Title|iPod Blue
Price|200
Stock|10
etc...
 
I managed to write a script (using foreach, etc.) that adds the products to the database but I spotted a little problem. If a product has a rather long title or description, the format looks like this:

Code: Select all

 
Title|iPod the pink one with
Title|protective case and 
Title|personalised wallpaper
Price|300
Stock|20
 
Title|iPod
Price|200
Stock|10
 
So the title field in database contains only the value "personalised wallpaper" rather than the full title e.g. "iPod the pink one with protective case and personalised wallpaper".

Is there a PHP function or something that allows me to concat or merge values based on same key?

Many thanks in advance! :)
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Array value concatenation?

Post by JakeJ »

Query the database, throw it in to an array and then $concat = $row['field1'] + $row['fields2'];

The + operator is a concatenation operator in php. If you need a space in there, just do this: $concat = $row['field1'] + ' ' + $row['fields2'];
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Array value concatenation?

Post by tr0gd0rr »

JakeJ wrote:The + operator is a concatenation operator in php.
No! Dot (".") is the string concatenation operator in PHP!

Not sure if you live in an alternate universe or if you have a bad case of the Mondays.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Array value concatenation?

Post by JakeJ »

I've completely lost my mind.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Array value concatenation?

Post by tr0gd0rr »

JakeJ wrote:I've completely lost my mind.
Darn! I was hoping you were in an alternate universe... sometimes I'd like to escape this one :D
Post Reply