-
PHP 8 에서 match문이 추가되었다.
$result = match($option) { 'option_1' => // 표현식, 'option_2','option_3' => // 표현식, 'default' => // 표현식, };
변수와 조건이 정확하게 일치(value 와 type)하면 표현식이 실행되고, 표현식의 결과를 리턴한다.
한 줄에 여러 옵션을 지정할 수 있으며 일치하는 값이 없는 경우 디폴트를 제공할 수 있다. 일치하는 항목이 없고 디폴트도 없으면 오류가 발생한다.
'php' 카테고리의 다른 글
guzzle, phpSpreadsheet 로 스크래핑 (0) 2023.09.12 http 헤더 추가하기 (0) 2023.09.08 Class .. Static (0) 2023.09.06 Class (0) 2023.09.06 지정인수 (0) 2023.09.06