title: PHP Array Declaration
body: <pre><code>for ($k = 0; $k &lt; $count; $k++) {
      $master[$k] = $namearray[$k], $streetarray[$k], $localityarray[$k], $regionarray[$k], $postalcodearray[$k], $phonearray[$k];
  }
  </code></pre>
  
  <p>I'd like to declare a new array and set values from other arrays already declared. I thought I could just loop through the keys and set the values but this doesn't work for me.  </p>
  
  <p>Full code below. I'm parsing yellow pages search results and trying to output search results into a csv file. In the code below I removed the loop and only added a few values to the array to make sure my bug wasn't something else.</p>
  
  <pre><code>&lt;?php
  
              // include required functions
              include('simple_html_dom.php');
  
              $url = "http://www.yellowpages.com/" . $_POST['city'] . '-' . $_POST['state'] . '-' . $_POST['postalcode'] . '/' . $_POST['category'] . '?g=' . $_POST['city'] . '%2C+' . $_POST['state'] . '+' . $_POST['postalcode'] . '&amp;q=' . $_POST['category'];
  
              // get DOM from URL
              $html = file_get_html($url);
  
  
              // find all business name
              foreach($html-&gt;find('h3.business-name') as $name)
                  //echo $name-&gt;innertext . '&lt;br /&gt;';
                  $namearray[] = $name-&gt;innertext;
  
              // find all business street address
              foreach($html-&gt;find('span.street-address') as $street) 
                  //echo $street-&gt;innertext . '&lt;br /&gt;';
                  $streetarray[] = $street-&gt;innertext;
  
              // find all business city
              foreach($html-&gt;find('span.locality') as $locality)
                  //echo $locality-&gt;innertext . '&lt;br /&gt;';
                  $localityarray[] = $locality-&gt;innertext;            
  
              // find all business state
              foreach($html-&gt;find('span.region') as $region)
                  //echo $region-&gt;innertext . '&lt;br /&gt;';
                  $regionarray[] = $region-&gt;innertext;            
  
              // find all business postal code
              foreach($html-&gt;find('span.postal-code') as $postalcode)
                  //echo $postalcode-&gt;innertext . '&lt;br /&gt;';
                  $postalcodearray[] = $postalcode-&gt;innertext;                
  
              // find all business phone
              foreach($html-&gt;find('span.business-phone') as $phone)
                  //echo $phone-&gt;innertext . '&lt;br /&gt;';
                  $phonearray[] = $phone-&gt;innertext;
  
          ?&gt;
          &lt;p&gt;Search results for: &lt;?php echo $_POST['category'] . ' ' . $_POST['city'] . ' ' . $_POST['state'] . ' ' . $_POST['postalcode'];  ?&gt;&lt;/p&gt;
          &lt;?php
              // Output results
              $count = count($namearray);
              for ($i = 0; $i &lt; $count; $i++) {
                  echo $namearray[$i] . '&lt;br /&gt;';
                  echo $streetarray[$i] . '&lt;br /&gt;';
                  echo $localityarray[$i] . ',' . $regionarray[$i] . ' ' . $postalcodearray[$i] . '&lt;br /&gt;';
                  echo $phonearray[$i] . '&lt;br /&gt;' . '&lt;br /&gt;';
              }
  
  
          $list = array (
              array($namearray[0], $streetarray[0], $localityarray[0], $regionarray[0], $postalcodearray[0], $phonearray[0]),
              array($namearray[1], $streetarray[1], $localityarray[1], $regionarray[1], $postalcodearray[1], $phonearray[1]),
              array($namearray[2], $streetarray[2], $localityarray[2], $regionarray[2], $postalcodearray[2], $phonearray[2]),
              array($namearray[3], $streetarray[3], $localityarray[3], $regionarray[3], $postalcodearray[3], $phonearray[3])
          );
  
          $fp = fopen('hrpsearch.csv', 'w');
  
          foreach ($list as $fields) {
              fputcsv($fp, $fields);
          }
  
          fclose($fp);
  
          ?&gt;
  </code></pre>