What are the advantages of phpfunction? Solution

Source: Internet
Author: User
What are the advantages of phpfunction? What are the advantages of PHP & nbsp; function & nbsp? & Nbsp; can the array be cleared automatically, variables be cleared, and MEMORY is cleared? $ Array & nbsp; array (www.google.com.hk, www.baidu.com, www.1.com, what are the advantages of php functions?
What are the advantages of PHP functions? Can the array be automatically cleared, variables cleared, and MEMORY cleared?



$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 a function, do you also need an unset array?
Or is the array automatically cleared when the first function is executed as long as return?


------ Solution --------------------
I don't know what it means for the two questions that follow you.
In fact, you can use functions to encapsulate function implementation. isn't the code better?
------ Solution --------------------
Unset and unset methods do not matter... the function writing method makes it easier for you to call the code structure at any time...

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.