mcloan Posted November 24, 2006 Share Posted November 24, 2006 This below script is a portion of a script that loops through a store locator a returns multiple address and phone numbers for multiple store locations. Can someone tell me the best way to add the values to an array and export them to csv? I have tried every thing and can not get it to work. I am assuming I need a multi dimensional array but can't seem to get it to work when I assign it in the loop.Please help. I really appreciate it.[code]<?phpforeach($Lines as $Line) { if (strstr($Line, 'addre')) // EXAMPLE ONLY! { $counter=$counter+1; $strTag="True"; $address=$Line; } if ($counter==6) { $phone=$Line; $strTag="False"; $counter=0; } if ($strTag!="False") { $counter=$counter+1; } if(!empty($dealername)&&!empty($address)) { //I need to assign to an associtive array here } } //I need to output the entire file to .csv here.?>[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted November 24, 2006 Share Posted November 24, 2006 The missing bit can be:[code=php:0]$multi_array[$dealername][] = array( 'address' => $address, 'phone' => $phone,);[/code]Then use var_dump($multi_array) to see what you've created :) This code assumes there can be many addresses for each dealername. Quote Link to comment Share on other sites More sharing options...
mcloan Posted November 24, 2006 Author Share Posted November 24, 2006 [quote author=btherl link=topic=116101.msg472875#msg472875 date=1164332463]The missing bit can be:[code=php:0]$multi_array[$dealername][] = array( 'address' => $address, 'phone' => $phone,);[/code]Then use var_dump($multi_array) to see what you've created :) This code assumes there can be many addresses for each dealername.[/quote]Works perfect. Thank you so much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.