What are the benefits of PHP function? Solution Solutions

Source: Internet
Author: User
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 ...
  • 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.