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] Link to comment https://forums.phpfreaks.com/topic/28289-help-i-just-cant-get-it-to-work-on-assigning-an-array/ 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. Link to comment https://forums.phpfreaks.com/topic/28289-help-i-just-cant-get-it-to-work-on-assigning-an-array/#findComment-129378 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. Link to comment https://forums.phpfreaks.com/topic/28289-help-i-just-cant-get-it-to-work-on-assigning-an-array/#findComment-129651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.