您好,欢迎访问一九零五行业门户网

php function 有什么好处?解决方案

php function 有什么好处?
php function 到底有什么好处? 可以自动清除数组,清除变量,清除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);
}
如果是function的话,是否也要unset数组?
还是只要return,下次执行function时会自动清空第一次执行function时的数组?
------解决方案--------------------
对于你后面的两个问题我不知道是什么意思。
其实简简单单的想,你用函数封装了功能实现,这样代码不更好看吗?
------解决方案--------------------
unset 不unset 两种方法都没关系...写成函数的方式 方便你随时调用 代码结构更清晰...
其它类似信息

推荐信息