Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Write array to .csv when different?

    Hello,

    I have two different arrays such as:

    Code:
    
        [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 ~

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Keep the columns, just add empty values tyo the csv.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar View Post
    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.


  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    PHP Code:
    $comma_seperated=implode(', ',$array~); 
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    Quote Originally Posted by timgolding View Post
    PHP Code:
    $comma_seperated=implode(', ',$array~); 
    Thanks for the other example tim ;-) ... what does the tilde do on the end of $array?
    Last edited by warlord; 03-13-2007 at 01:52 PM.

  • #6
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    oops sorry thats a mistake. Remove the tidle
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •