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

(새 문서: ==개요== ;PHP conditional operator, PHP ternary operator ;PHP 조건부 연산자, PHP 삼항 연산자 <source lang='PHP'> $score = 50; $grade = $score > 80 ? 'A' : 'B'; echo $grad...)
 
 
(사용자 2명의 중간 판 7개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;PHP conditional operator, PHP ternary operator
;PHP conditional operator, PHP ternary operator
;PHP 조건부 연산자, PHP 삼항 연산자
;PHP 조건부 연산자, PHP 삼항 연산자
<source 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>
</source>
<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>


==같이 보기==
==같이 보기==
* [[조건부 연산자]]
* [[조건부 연산자]]
* [[PHP null 합체 연산자]]
* [[PHP 널 병합 연산자]]
* [[PHP 단축 조건부 연산자]]
* [[PHP 비교 연산자 목록]]


==참고==
==참고==
* http://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
* https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary


[[분류: PHP 연산자]]
[[분류: PHP 연산자]]

2023년 11월 27일 (월) 00:17 기준 최신판

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 }}