Array problems.

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


The $ url here is an array and its storage address
Use the snoopy method, $ netbot-> fetchlinks ($ val) to get all links of this url
So, I want to put all links in an array.

$ Netbot-> results returns a one-dimensional array.

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

In this way, a multi-dimensional array is obtained.

The link in is only the links of the url he accessed for the first time.



I want this $ urlarray subscript to be automatically transferred.
When obtaining the second url, you can inherit the subscript above when assigning values, and convert $ urlarray to a one-dimensional array,

How can this be achieved?


Reply to discussion (solution)

If condition?

Foreach ($ netbot-> results as $ v ){
$ Urlarray [] = $ v;
}

No matter what $ netbot-> results gets
You exit after $ netbot-> fetchlinks ($ val) fails.
Then, the subsequent $ val in the $ url will have no chance to fetchlinks.
So we should continue the loop instead of exit.

The url you fetchlinks to is stored in $ urlarray and is not involved in subsequent searches.
Therefore, at most $ url traversal ends. In this way, all the level-1 connections that may exist in $ url are obtained.

Depending on your needs, it seems that you should keep following the obtained connections.

Assume that $ netbot-> results is a join one-dimensional array, 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 }}

Is there a wrong break and exit?

Did the landlord give up?
It should be recycled in the first condition of 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.