...

View Full Version : Write array to .csv when different?



warlord
03-13-2007, 07:51 AM
Hello,

I have two different arrays such as:





[name] => John
[city] => New York
[zipcode] => unknown
[region] => East
[year] => 2007
[gender] => Male
[experience] => unknown

(and)

[name] => Lisa
[city] => Seattle
[zipcode] => unknown
[region] => West
[year] => 2007
[gender] => Female
[job] => Sales
[salary] => unknown
[experience] => unknown

Notice the two extra keys on the last one (job and salary). My question is when I write the arrays to a .csv file how to I keep the columns from getting fouled up when one array is different than another? Sometimes the array might have 5 keys and the next might have 10, etc ...

Thanks ~

marek_mar
03-13-2007, 08:49 AM
Keep the columns, just add empty values tyo the csv.

warlord
03-13-2007, 01:28 PM
Keep the columns, just add empty values tyo the csv.

Thanks marek_mar .... I decided to use an array_merge to handle it and it works out pretty good.

;)

timgolding
03-13-2007, 01:40 PM
$comma_seperated=implode(', ',$array~);

warlord
03-13-2007, 01:48 PM
$comma_seperated=implode(', ',$array~);


Thanks for the other example tim ;-) ... what does the tilde do on the end of $array?

timgolding
03-13-2007, 02:36 PM
oops sorry thats a mistake. Remove the tidle



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum