What are the benefits of PHP function?
What are the benefits of PHP function? can automatically clear the array, clear the variable, clear memory?
$array = Array (' http://www.google.com.hk ', ' http://www.baidu.com ', ' http://www.1.com/', ' http://www.yahoo.com.cn ');
foreach ($array as $url) {
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (Windows; U Windows NT 5.1; En-us; rv:1.9.2) gecko/20100115 firefox/3.6 (. NET CLR 3.5.30729) ');
$html = curl_exec ($ch);
Curl_close ($ch);
echo $html. '
';
$html = NULL;
Unset ($html);
}
function get_html ($url) {
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (Windows; U Windows NT 5.1; En-us; rv:1.9.2) gecko/20100115 firefox/3.6 (. NET CLR 3.5.30729) ');
$html = curl_exec ($ch);
Curl_close ($ch);
return $html;
}
$array = Array (' http://www.google.com.hk ', ' http://www.baidu.com ', ' http://www.1.com/', ' http://www.yahoo.com.cn ');
foreach ($array as $url) {
Get_html ($url);
}
If it is function, do you want to unset the array as well?
Or simply return, the next time the function is executed, the array will be automatically emptied the first time the function is executed?
------Solution--------------------
I don't know what that means for the two questions behind you.
In fact, simple thinking, you use a function to encapsulate the implementation of the function, so that the code is not better to see it?
------Solution--------------------
Unset not unset two ways is ok ... Write functions in a way that makes it easier for you to call the code structure more clearly ...