我有這樣的代碼:將三元運算符分解爲if語句?
$get_options = isset($options['big_heading']) ? ($options['big_heading']) : '' ;
但我很難讀這個三元運算符,所以我怎麼能分解成一個if語句?對不起,我的好評問題... 謝謝!
我有這樣的代碼:將三元運算符分解爲if語句?
$get_options = isset($options['big_heading']) ? ($options['big_heading']) : '' ;
但我很難讀這個三元運算符,所以我怎麼能分解成一個if語句?對不起,我的好評問題... 謝謝!
你的代碼等於:
if(isset($options['big_heading'])){
$get_options = $options['big_heading'];
} else {
$get_options = '';
}
這句法總是喜歡:$foo = (condition) ? if_its_true : if_its_not_true ;
這是一樣的
$get_options = isset($options['big_heading']) ? ($options['big_heading']) : '' ;
這
if(isset($options['big_heading'])) {
$get_options = $options['big_heading'];
} else {
$get_options = '';
}
if(isset($options['big_heading'])) {
$get_options = $options['big_heading'];
} else {
$get_options = '';
}
$get_options = "";
if(isset($options['big_heading']))
{
$get_options = $options['big_heading']
}
$get_options = '' ;
if (isset($options['big_heading'])) {
$get_options = $options['big_heading'];
}
在這裏你去...
if (isset($options['big_heading'])){
$get_options = $options['big_heading'];
else{
$get_options = '';
}
嗯,使用三元運算符是罰款和可讀性比if/else語句更好。那麼,這是主觀的。 – Leri
這裏發生了什麼垃圾,你認爲這是正確的空間問題。 :( –
嗯Neeraj辛格不是每個人都知道PHP像你這樣做,我們有些人仍然在學習這個東西... –