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