0

if文をカットしてベストウェイにしたい

if ($box === 1) {
    $message['sender'] = $data['user_profile_id'];
    $message['receiver'] = $data['to_user_profile_id'];
} else {
    $message['sender'] = $data['to_user_profile_id'];
    $message['receiver'] = $data['user_profile_id'];
}

1 回の試行:

$message['sender'] = $box === 1 ? $data['user_profile_id'] : $data['to_user_profile_id'];
$message['receiver'] = $box === 1 ? $data['to_user_profile_id'] : $data['user_profile_id'];

送信者/受信者変数を切り替えるより良い方法はありますか?

4

1 に答える 1