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]
Link to comment
Share on other sites

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
Share on other sites

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.