Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:18:13+00:00 2026-06-09T13:18:13+00:00

for ($k = 0; $k < $count; $k++) { $master[$k] = $namearray[$k], $streetarray[$k], $localityarray[$k],

  • 0
for ($k = 0; $k < $count; $k++) {
    $master[$k] = $namearray[$k], $streetarray[$k], $localityarray[$k], $regionarray[$k], $postalcodearray[$k], $phonearray[$k];
}

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.

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.

<?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'] . '&q=' . $_POST['category'];

            // get DOM from URL
            $html = file_get_html($url);


            // find all business name
            foreach($html->find('h3.business-name') as $name)
                //echo $name->innertext . '<br />';
                $namearray[] = $name->innertext;

            // find all business street address
            foreach($html->find('span.street-address') as $street) 
                //echo $street->innertext . '<br />';
                $streetarray[] = $street->innertext;

            // find all business city
            foreach($html->find('span.locality') as $locality)
                //echo $locality->innertext . '<br />';
                $localityarray[] = $locality->innertext;            

            // find all business state
            foreach($html->find('span.region') as $region)
                //echo $region->innertext . '<br />';
                $regionarray[] = $region->innertext;            

            // find all business postal code
            foreach($html->find('span.postal-code') as $postalcode)
                //echo $postalcode->innertext . '<br />';
                $postalcodearray[] = $postalcode->innertext;                

            // find all business phone
            foreach($html->find('span.business-phone') as $phone)
                //echo $phone->innertext . '<br />';
                $phonearray[] = $phone->innertext;

        ?>
        <p>Search results for: <?php echo $_POST['category'] . ' ' . $_POST['city'] . ' ' . $_POST['state'] . ' ' . $_POST['postalcode'];  ?></p>
        <?php
            // Output results
            $count = count($namearray);
            for ($i = 0; $i < $count; $i++) {
                echo $namearray[$i] . '<br />';
                echo $streetarray[$i] . '<br />';
                echo $localityarray[$i] . ',' . $regionarray[$i] . ' ' . $postalcodearray[$i] . '<br />';
                echo $phonearray[$i] . '<br />' . '<br />';
            }


        $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);

        ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:18:14+00:00Added an answer on June 9, 2026 at 1:18 pm

    Try:

    $master = array();
    for ($k = 0; $k < $count; $k++) {
        $master[$k] = array
            ( $namearray[$k]
            , $streetarray[$k]
            , $localityarray[$k]
            , $regionarray[$k]
            , $postalcodearray[$k]
            , $phonearray[$k]
            );
    }
    

    This will create a new two-dimensional array for you with associated keys for every child array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TOPIC_COUNT_SQL = SELECT COUNT(*) FROM topics_topic WHERE topics_topic.object_id = maps_map.id AND topics_topic.content_type_id = %s
SELECT COUNT(`t`.id) FROM `product` `t` INNER JOIN `category` `c1` ON ( `c1`.id ='15' )
How to count the number of occurrence of a values in a dictionary in
ASP.NET newbie here. When on a page I'd like to set the corresponding menu
I am setting a column-count to 2 in my simple-page-master. I am using xsl-fo
I have a Master Table and a Detail Table(like Categories and Products) in SQL
I have tried a lot to figure how to get the count from two
I DON't want to count NULL values. Because NULL should not be equal to
I need to check whether an event is fired from the master page or
bash master needed... To compare mysqldumps from multiple dates, I need sql GROUP BY,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.