Array problem.

Source: Internet
Author: User
The code is as follows
foreach ($url as $val) {if ($netbot->fetchlinks ($val)) {$urlarray [] = $netbot->results;} Else{echo "Error:". $netbot->error;exit;}}


This is an array, storing the address
Through the Snoopy method, $netbot->fetchlinks ($val) to get all the link for this URL
So, I want to put all the link in an array

$netbot->results Returns a one-dimensional array

The question now is: $urlarray [] = $netbot->results;

This method assigns a value that gets a multidimensional array

The link in it is only the first time he visited the URL links



I want this $urlarray to be transferred automatically.
When you get the second URL, when you assign a value, you can inherit the subscript above, transforming $urlarray into a 1-dimensional array.

How can this be achieved?


Reply to discussion (solution)

The IF condition inside again cycle?

foreach ($netbot->results as $v) {
$urlarray [] = $v;
}

First, whatever $netbot->results got.
You exit after $netbot->fetchlinks ($val) failed.
Then there's no chance of any further fetchlinks in the $url $val.
So should not exit and should continue to circulate

Every time you fetchlinks to the URL is stored in the $urlarray and does not participate in subsequent lookups
So at the very end of the $url traversal is over. This takes all the first-level connections that may exist in the $url

Look at your needs, it seems that you should follow the access to the connection has been deep down

Suppose $netbot->results is a one-dimensional array of connections, name
for ($i =0; $i

  if ($netbot->fetchlinks ($val)) {//If there is a link    $url = array_merge ($url, $netbot->results);//Add the connection to the search queue  }}

Did you get the wrong break and exit?

Did the landlord give up?
It should be recycled in the first condition of the IF

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.