"PHP 조건부 연산자"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
2번째 줄: 2번째 줄:
;PHP conditional operator, PHP ternary operator
;PHP conditional operator, PHP ternary operator
;PHP 조건부 연산자, PHP 삼항 연산자
;PHP 조건부 연산자, PHP 삼항 연산자
<syntaxhighlight lang='PHP'>
<syntaxhighlight lang='PHP' run>
$score = 50;
$score = 50;
$grade = $score > 80 ? 'A' : 'B';
$grade = $score > 80 ? 'A' : 'B';
echo $grade;
echo $grade;
# B
</syntaxhighlight>
<syntaxhighlight lang='php' run>
$_POST = ['action' => 'edit'];
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
echo $action;
</syntaxhighlight>
<syntaxhighlight lang='php' run>
$_POST = [];
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
echo $action;
</syntaxhighlight>
</syntaxhighlight>



2021년 7월 16일 (금) 10:29 판

1 개요

PHP conditional operator, PHP ternary operator
PHP 조건부 연산자, PHP 삼항 연산자
$score = 50;
$grade = $score > 80 ? 'A' : 'B';
echo $grade;
$_POST = ['action' => 'edit'];
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
echo $action;
$_POST = [];
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
echo $action;

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}