<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('image_thumb')){
function image_thumb($courseBanner, $userId){
$CI =& get_instance();
$filename_ext = pathinfo($courseBanner, PATHINFO_EXTENSION);
$course_thumb_Banner = preg_replace('/^(.*)\.' . $filename_ext . '$/', '$1_thumb.' . $filename_ext, $courseBanner);
$url = base_url()."private/".$userId."/".$course_thumb_Banner;
$headers=get_headers($url);
$is_banner_there = stripos($headers[0],"200 OK")?true:false;
$url = ($is_banner_there)?$url: base_url()."public/images/placeholder.jpg";
return $url;
}
}
在上面的代碼有時候$ courseBanner不會來,所以那個時候我想發這個base_url()."public/images/placeholder.jpg
怎麼辦?當一個參數不起作用時該怎麼辦?
它被稱爲設置默認;看到這個:http://stackoverflow.com/questions/9166914/using-default-arguments-in-a-function – WillardSolutions
'function image_thumb($ userId,$ courseBanner = base_url()。「public/images/placeholder.jpg」 ){' –
[在函數中使用默認參數]可能的重複(http://stackoverflow.com/questions/9166914/using-default-arguments-in-a-function) – WillardSolutions