Jump to content

Help I Just Can't Get It To Work On Assigning An Array


mcloan

Recommended Posts

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]
<?php
foreach($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]
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 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.