0

if/elseで配列の値を変更するには?

コード:

    public function getActions()
{
    return array(
    'dislike' => array(
        'enabled' => true,
        'action_type_id' => 2,
        'phrase' => Phpfox::getPhrase('like.dislike'),
        'phrase_in_past_tense' => 'disliked',
        'item_phrase' => 'comment',
        'item_type_id' => 'feed',
        'table' => 'feed_comment',
        'column_update' => 'total_dislike',
        'column_find' => 'feed_comment_id',
        'where_to_show' => array('', 'photo')           
        )
    );
}

if/elseで変更するコードを挿入する方法は?

if (Phpfox::isMobile())
    {
        'phrase' => Phpfox::getPhrase('mobiletemplate.unlike_icon'),
    }
else
    {
        'phrase' => Phpfox::getPhrase('like.dislike'),
    }

助けてくれてありがとう!

4

4 に答える 4

2

三項演算子を使用してインライン チェックを実行します。

public function getActions()
{
    return array(
    'dislike' => array(
        'enabled' => true,
        'action_type_id' => 2,
        'phrase' => Phpfox::getPhrase(
            Phpfox::isMobile()
            ? 'mobiletemplate.unlike_icon'
            : 'like.dislike'
        ),
        'phrase_in_past_tense' => 'disliked',
        'item_phrase' => 'comment',
        'item_type_id' => 'feed',
        'table' => 'feed_comment',
        'column_update' => 'total_dislike',
        'column_find' => 'feed_comment_id',
        'where_to_show' => array('', 'photo')           
        )
    );
}
于 2014-08-19T14:47:48.290 に答える
0

より単純ですが、この場合のみ:

'phrase' => Phpfox::getPhrase(Phpfox::isMobile()? 'mobiletemplate.unlike_icon' : 'like.dislike'),
于 2014-08-19T14:48:20.410 に答える
-3

このようなもの

'phrase' => call_user_func(function(){ 
   if(Phpfox::isMobile()){
      return Phpfox::getPhrase('mobiletemplate.unlike_icon');
   }else{
      return Phpfox::getPhrase('like.dislike');
   }
 }), ...
于 2014-08-19T14:48:19.560 に答える