2016-08-18 17 views
-1

どうすればこのように書くことができますか?php else for function shorthand

$abc = file_get_contents('one.txt'); 
if($abc !== '') 
{ 
msg($abc); 
} else { 
msg('nope'); 
} 

私が試した:

$abc = file_get_contents('one.txt'); 
if($abc !== '') ? msg($abc) : msg('nope'); 

または

$abc = file_get_contents('one.txt'); 
msg if($abc !== '') ? $abc : 'nope'; 

ない作業を、助けてください!

答えて

4

三項式を書くときには、ifというキーワードを使用しないでください。

($abc != '') ? msg($abc) : msg('nope'); 

または

msg($abc != '' ? $abc : 'nope'); 
+0

'MSG($ abcの$ ABC:? 'いいえ')'? – Progrock

0
<?php 
msg(($abc = file_get_contents('blah.txt')) ? $abc : 'Nope'); 

私はエラーを抑制したいが、そうでないかもしれないん

msg(($abc = @file_get_contents('blah.txt')) ? $abc : 'Nope');