What is this?이게 뭐야?
This is a collection of questions that come up every now and then about syntax in PHP.이것은 PHP의 구문에 관한 질문의 모음입니다. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.또한 커뮤니티 위키이므로 모든 사용자가 이 목록 관리에 참여하도록 초대됩니다.
Why is this?왜 이러한가?
It used to be hard to find questions about operators and other syntax tokens.연산자 및 기타 구문 토큰에 대한 질문은 찾기 어려웠습니다.¹¹
The main idea is to have links to existing questions on Stack Overflow, so it’s easier for us to reference them, not to copy over content from the PHP Manual.Stack Overflow의 기존 질문에 대한 링크가 있어야 하기 때문에 PHP 매뉴얼에서 콘텐츠를 복사하는 것이 아니라 참조하기가 더 쉽습니다.
Note: Since January 2013, Stack Overflow does support special characters.주의: 2013년 1월부터 Stack Overflow는 특수 문자를 지원합니다. Just surround the search terms by quotes, e.g. [php] "==" vs "==="
검색어를 따옴표로 둘러싸기만 하면 됩니다.
What should I do here?여기서 뭘 해야 하죠?
If you have been pointed here by someone because you have asked such a question, please find the particular syntax below.만약 당신이 그런 질문을 해서 누군가에게 여기를 지적받았다면, 아래의 특정 구문을 찾아보세요. The linked pages to the PHP manual along with the linked questions will likely answer your question then.PHP 매뉴얼에 링크된 페이지와 링크된 질문이 당신의 질문에 대답할 것입니다. If so, you are encouraged to upvote the answer.그렇다면 답변을 상향 투표하는 것이 좋습니다. This list is not meant as a substitute for the help others provided.이 목록은 다른 사용자가 제공한 도움말을 대체하는 것이 아닙니다.
The List리스트
If your particular token is not listed below, you might find it in the List of Parser Tokens.특정 토큰이 아래에 나열되지 않은 경우 파서 토큰 목록에서 찾을 수 있습니다.
&
Bitwise Operators or References비트 연산자 또는 참조
- What does it mean to start a PHP function with an ampersand?앰퍼샌드를 사용하여 PHP 함수를 시작하는 것은 무엇을 의미합니까?
- Understanding PHP & (ampersand, bitwise and) operatorPHP & (앰퍼샌드, 비트 및) 연산자에 대해
- PHP “&” operatorPHP “&” 연산자
- Difference between & and && in PHPPHP와 &&의 차이점
- What does “&” mean here in PHP?여기 PHP에서 &는 무엇을 의미합니까?
- What does “&” mean in this case?이 경우 &은 무엇을 의미합니까?
- What does the “&” sign mean in PHP?PHP에서 & 기호는 무엇을 의미합니까?
- What does this signature mean (&) in PHP?이 시그니처는 PHP에서 (&)의 의미입니까?
- How does the “&” operator work in a PHP function?“&” 연산자는 PHP 함수에서 어떻게 작동합니까?
- What does & in &2 mean in PHP?& in & 2는 PHP에서 무엇을 의미합니까?
- When should I use a bitwise operator?비트 연산자는 언제 사용해야 합니까?
- Is there ever a need to use ampersand in front of an object? (&$)오브젝트 앞에 앰퍼샌드를 사용할 필요가 있습니까?(&$)
- Reference assignment operator in PHP, =&PHP의 참조 할당 연산자 =&
- What do the “=&” and “&=” operators in PHP mean?PHP에서 “=&” 및 “=” 연산자는 무엇을 의미합니까?
- What do the ‘&=’ and ‘=&’ operators do?‘&=’ 및 ‘=&’ 연산자의 역할은 무엇입니까?
- What does =& mean in PHP?PHP에서 = &은 무엇을 의미합니까?
- What do the “=&” and “&=” operators in PHP mean?PHP에서 “=&” 및 “=” 연산자는 무엇을 의미합니까?
- What do the ‘&=’ and ‘=&’ operators do?‘&=’ 및 ‘=&’ 연산자의 역할은 무엇입니까?
- ‘AND’ vs ‘&&’ as operator연산자로서의 ‘AND’ vs ‘&’
- Difference between & and && in PHPPHP와 &&의 차이점
- Is there any difference between “and” and “&&” operators in PHP?PHP에서 “and” 연산자와 “&” 연산자는 어떤 차이가 있습니까?
- PHP – and / or keywordsPHP – 및/또는 키워드
- What does the percent sign mean in PHP?PHP에서 퍼센트 기호는 무엇을 의미합니까?
- What is the PHP operator % and how do I use it in real-world examples?PHP 연산자 %는 무엇이며 실제 예에서는 어떻게 사용합니까?
@
Error Control Operators오류 제어 연산자
- What is the use of the @ symbol in PHP?PHP에서 @ 기호의 용도는 무엇입니까?
- ‘At’ symbol before variable name in PHP: @$_POSTPHP의 변수 이름 앞에 있는 ‘At’ 기호: @$_POST
- PHP functions and @functionsPHP 함수 및 @functions
- Should I use @ in my PHP code?PHP 코드에 @를 사용해야 합니까?
- What does @ mean in PHP?PHP에서 @는 무엇을 의미합니까?
- What are the PHP operators “?” and “:” called and what do they do?호출된 PHP 연산자 “?”와 “:”는 무엇이며, 그들은 무엇을 합니까?
- ?: operator (the ‘Elvis operator’) in PHP?: PHP의 연산자(‘Elvis 연산자’)
- Where can I read about conditionals done with “?” and “:” (colon)?“?”와 “:”(콜론)으로 이루어진 조건어는 어디에서 확인할 수 있습니까?
- Using PHP 5.3 ?: operatorPHP 5.3 ?: 연산자 사용
??
Null Coalesce Operator (since PHP 7)Null 병합 연산자(PHP 7 이후)
?string
?int
?array
?bool
?float
Nullable return type declaration (since PHP 7.1)PHP 7.1 이후 null 반환 형식 선언
- Nullable return type declaration무효 반환 유형 선언
- Nullable parameter type declarationnull 매개 변수 형식 선언
- php method argument type hinting with question mark (?type)php 메서드 인수 유형 물음표(?type)를 사용한 힌트
:
Alternative syntax for control structures, Ternary Operator, Return Type Declaration제어 구조, 3진 연산자, 반환 유형 선언에 대한 대체 구문
- What is “:” in PHP?PHP의 “:”는 무엇입니까?
- What does “:” mean in PHP?PHP에서 “:”는 무엇을 의미합니까?
- Colon after method declaration?메서드 선언 후 콜론?
::
Scope Resolution Operator스코프 분해능 연산자
- What do two colons mean in PHP?PHP에서 두 개의 콜론은 무엇을 의미합니까?
- What’s the meaning of the PHP token name T_PAAMAYIM_NEKUDOTAYIM?PHP 토큰명 T_PAAMAYIM_NEKUDOTAYIM의 의미는 무엇입니까?
- What’s the difference between :: (double colon) and -> (arrow) in PHP?PHP의 ::(이중 콜론)과 ->(화살표)의 차이점은 무엇입니까?
- What exactly are late static bindings in PHP?PHP에서 레이트 스태틱바인딩이란 정확히 무엇입니까?
- static::staticFunctionName()스태틱: static Function Name()
- Unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_NS_Separator예기치 않은 T_PAAMAYIM_NEKUDOTAYIM. T_NS_Separator가 필요합니다.
- Backslash in PHP — what does it mean?PHP의 백슬래시 – 무슨 뜻이죠?
- What does a (backslash) do in PHP (5.3+)?(백슬래시)는 PHP(5.3+)에서 무엇을 합니까?
->
Classes And Objects클래스와 오브젝트
- What is the “->” PHP operator called?“->” PHP 연산자를 뭐라고 합니까?
- Where do we use the object operator “->” in PHP?PHP에서는 오브젝트 연산자 “->”를 어디에 사용할 수 있습니까?
- What’s the difference between :: (double colon) and -> (arrow) in PHP?PHP의 ::(이중 콜론)과 ->(화살표)의 차이점은 무엇입니까?
- What does the PHP syntax $var1->$var2 mean?PHP 구문 $var1-> $var2는 무엇을 의미합니까?
- What does “->” mean/refer to in PHP?“->”는 PHP에서 무엇을 의미합니까?
=>
Arrays어레이
- What does “=>” mean in PHP?PHP에서 “=>”는 무엇을 의미합니까?
- Use of => in PHPPHP에서 => 사용
- What does $k => $v in foreach($ex as $k=>$v) mean?$k = > $v as $k = > $v)는 무엇을 의미합니까?
- How does the bitwise operator XOR (‘^’) work?비트 연산자 XOR(‘^’)은 어떻게 작동합니까?
- What does ^ mean in PHP?PHP에서 ^는 무엇을 의미합니까?
<<<
Heredoc or NowdocEledoc 또는 Nowdoc
- What does <<<END mean in PHP?PHP에서 << END>는 무엇을 의미합니까?
- PHP expression <<<EOBPHP 표현식 << EOB
- In PHP, what does “<<<” represent?PHP에서 “<<“는 무엇을 의미합니까?
- Using <<<CON in PHPPHP에서 <<CON 사용
- What’s this kind of syntax in PHP?PHP의 구문은 무엇입니까?
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?PHP 등호(== 이중 등호)와 아이덴티티(=== 삼중 등호) 비교 연산자는 어떻게 다릅니까?
- PHP != and == operatorsPHP != 및 == 연산자
- The 3 different equals3가지 다른 점은
- Type-juggling and (strict) greater/lesser-than comparisons in PHPPHP의 유형 조정 및 (엄격한) 크기/낮은 비교
===
Comparison Operators비교 연산자
- What does “===” mean?“===”의 의미는 무엇입니까?
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?PHP 등호(== 이중 등호)와 아이덴티티(=== 삼중 등호) 비교 연산자는 어떻게 다릅니까?
- The 3 different equals3가지 다른 점은
- Type-juggling and (strict) greater/lesser-than comparisons in PHPPHP의 유형 조정 및 (엄격한) 크기/낮은 비교
!==
Comparison Operators비교 연산자
- What does !== comparison operator in PHP mean?PHP에서 !== 비교 연산자는 무엇을 의미합니까?
- Is there a difference between !== and != in PHP?PHP에서는 !==와 !=의 차이가 있습니까?
- PHP != and == operatorsPHP != 및 == 연산자
- Is there a difference between !== and != in PHP?PHP에서는 !==와 !=의 차이가 있습니까?
- comparing, !== versus !=비교, !== 대 !=
- What is the difference between <> and !=<< 고객명 >>과 !=의 차이점은 무엇입니까?
- PHP operator <>PHP 연산자 <>
- PHP’s <> operatorPHP의 <> 연산자
- What is the difference between <> and !=<< 고객명 >>과 !=의 차이점은 무엇입니까?
- Type-juggling and (strict) greater/lesser-than comparisons in PHPPHP의 유형 조정 및 (엄격한) 크기/낮은 비교
<=>
Comparison Operators (since PHP 7.0)비교 연산자(PHP 7.0 이후)
- What is the difference between the and operators?와 연산자의 차이점은 무엇입니까?
- What Does Using A Single Pipe ‘ ‘ In A Function Argument Do?함수 인수에 단일 파이프를 사용하는 방법
- What is the difference between the and operators?와 연산자의 차이점은 무엇입니까?
- PHP – and / or keywordsPHP – 및/또는 키워드
- What exactly does mean?정확히 무슨 뜻이죠?
- The behaviour of the or operator in PHPPHP에서 또는 연산자의 동작
+
Arithmetic Operators, Array Operators산술 연산자, 배열 연산자
+=
and 그리고.-=
Assignment Operators할당 연산자
- What is += used for?+=는 무엇에 사용됩니까?
- What does `$page -= 1` in my PHP document mean?내 PHP 문서에서 ‘$page -= 1’은 무엇을 의미합니까?
++
and 그리고.--
Incrementing/Decrementing Operators연산자 증가/감소 연산자
- What is the difference between .= and += in PHP?PHP에서 .=와 +=의 차이점은 무엇입니까?
- To understand a line of PHPPHP 행을 이해하려면
- Difference between period and comma when concatenating with echo versus return?에코와 연결할 때의 마침표와 쉼표의 차이와 리턴의 차이
- What does a . (dot) do in PHP?.(닷)은 PHP에서 무엇을 합니까?
- What does $$ (dollar dollar or double dollar) mean in PHP?PHP에서 $$(달러 또는 더블달러)는 무엇을 의미합니까?
- what is “$$” in PHPPHP의 “$$”란
- $function() and $$variable$function() 및 $$functions
- What does this symbol mean in PHP <?이 기호는 PHP <에서 무엇을 의미합니까?==
- What does ‘<?‘<‘가 뭐죠?=’ mean in PHP?=’는 PHP에서 의미합니까?
- What does <?= mean?<?=>는 무슨 뜻입니까?
[]
Arrays (short syntax since PHP 5.4)어레이(PHP 5.4 이후 짧은 구문)
- PHP arrays…PHP 배열… What is/are the meaning(s) of an empty bracket?빈 괄호의 의미는 무엇입니까?
- What is the meaning of [][ ]의 의미는 무엇입니까?
- Php array_push() vs myArray[]Php array_push() vs myArray[]
- What does [] mean when reading from a PHP array?PHP 어레이에서 읽을 때 []는 무엇을 의미합니까?
- Shorthand for arrays: literal 배열의 줄임말: 리터럴
$var = []
empty array빈 배열
<?
Opening and Closing tags태그 열기 및 닫기
..
Double-dot character range이중 도트 문자 범위
...
Argument unpacking (since PHP 5.6)인수 언팩(PHP 5.6 이후)
**
Exponentiation (since PHP 5.6)지수화(PHP 5.6 이후)
#
One-line shell-style comment한 줄 셸 스타일의 코멘트
?->
NullSafe Operator Calls (since PHP 8.0)NullSafe 오퍼레이터 호출(PHP 8.0 이후)
질문에 대한 답변
Incrementing / Decrementing Operators연산자 증가/감소
++
increment operator증분 연산자
--
decrement operator감소 연산자
Example Name Effect --------------------------------------------------------------------- ++$a Pre-increment Increments $a by one, then returns $a. $a++ Post-increment Returns $a, then increments $a by one. --$a Pre-decrement Decrements $a by one, then returns $a. $a-- Post-decrement Returns $a, then decrements $a by one.
These can go before or after the variable.이러한 값은 변수 앞 또는 뒤에 있을 수 있습니다.
If put before the variable, the increment/decrement operation is done to the variable first then the result is returned.변수 앞에 놓으면 변수에 대해 먼저 증가/감소 연산이 수행된 후 결과가 반환됩니다. If put after the variable, the variable is first returned, then the increment/decrement operation is done.변수 뒤에 입력하면 변수가 먼저 반환되고 다음으로 증분/감소 작업이 수행됩니다.
For example:예를 들어 다음과 같습니다.
$apples = 10; for ($i = 0; $i < 10; ++$i) { echo 'I have ' . $apples-- . " apples. I just ate one.n"; }
In the case above 위의 경우++$i
is used, since it is faster.더 빠르기 때문에 사용합니다. $i++
would have the same results.같은 결과를 얻을 수 있습니다.
Pre-increment is a little bit faster because it really increments the variable and after that ‘returns’ the result.사전 인크리먼트는 변수를 실제로 인크리먼트하고 그 후에 결과를 ‘반환’하기 때문에 조금 더 빠릅니다. Post-increment creates a special variable, copies there the value of the first variable and only after the first variable is used, replaces its value with second’s.포스트 인크리먼트는 특별한 변수를 생성하여 첫 번째 변수의 값을 복사하고 첫 번째 변수를 사용한 후에만 해당 값을 두 번째 변수의 값으로 바꿉니다.
However, you must use 단, 다음 명령어를 사용해야 합니다.$apples--
, since first, you want to display the current number of apples, and then you want to subtract one from it.먼저 현재 사과 수를 표시한 다음 사과에서 하나를 빼려고 합니다.
You can also increment letters in PHP:PHP에서 문자를 늘릴 수도 있습니다.
$i = "a"; while ($i < "c") { echo $i++; }
Once 한번만z
is reached 도달했다aa
is next, and so on.다음 등입니다.
Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.문자 변수는 증분할 수 있지만 감소시킬 수 없습니다.그 경우에도 지원되는 것은 플레인 ASCII 문자(a~z 및 A~Z)뿐입니다.
Stack Overflow Posts:스택 오버플로우 투고:
Bitwise Operator비트 연산자
What is a bit?뭐가 조금인데? A bit is a representation of 1 or 0.비트는 1 또는 0을 나타냅니다. Basically OFF(0) and ON(1)기본적으로 OFF(0) 및 ON(1)
What is a byte?바이트란? A byte is made up of 8 bits and the highest value of a byte is 255, which would mean every bit is set.바이트는 8비트로 구성되며 바이트의 최고값은 255로, 이는 모든 비트가 설정되어 있음을 의미합니다. We will look at why a byte’s maximum value is 255.바이트의 최대값이 255인 이유를 살펴보겠습니다.
------------------------------------------- 1 Byte ( 8 bits ) ------------------------------------------- Place Value 128 64 32 16 8 4 2 1 -------------------------------------------
This representation of 1 Byte이 1바이트의 표현
1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255 (1 Byte) 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255 (1 바이트)
A few examples for better understanding이해를 돕기 위한 몇 가지 예
The “AND” operator: “AND” 연산자:&
$a = 9; $b = 10; echo $a & $b;
This would output the number 8. Why?숫자 8이 출력됩니다. 왜일까요? Well let’s see using our table example.그럼 표의 예를 사용해 보겠습니다.
------------------------------------------- 1 Byte ( 8 bits ) ------------------------------------------- Place Value 128 64 32 16 8 4 2 1 ------------------------------------------- $a 0 0 0 0 1 0 0 1 ------------------------------------------- $b 0 0 0 0 1 0 1 0 ------------------------------------------- & 0 0 0 0 1 0 0 0 -------------------------------------------
So you can see from the table the only bit they share together is the 8 bit.표에서 볼 수 있듯이 8비트밖에 공유되지 않았습니다.
Second example두 번째 예
$a = 36; $b = 103; echo $a & $b; // This would output the number 36. $a = 00100100 $b = 01100111
The two shared bits are 32 and 4, which when added together return 36.2개의 공유 비트는 32와 4이며, 합하면 36이 반환됩니다.
The “Or” operator: “Or” 연산자:
$a = 9; $b = 10; echo $a $b;
This would output the number 11. Why?숫자 11이 출력됩니다. 왜요?
------------------------------------------- 1 Byte ( 8 bits ) ------------------------------------------- Place Value 128 64 32 16 8 4 2 1 ------------------------------------------- $a 0 0 0 0 1 0 0 1 ------------------------------------------- $b 0 0 0 0 1 0 1 0 ------------------------------------------- 0 0 0 0 1 0 1 1 -------------------------------------------
You will notice that we have 3 bits set, in the 8, 2, and 1 columns.8열, 2열 및 1열에 3비트가 설정되어 있는 것을 알 수 있습니다. Add those up: 8+2+1=11.더하면 8+2+1=11이다.
<=>
Spaceship Operator우주선 오퍼레이터
Added in PHP 7PHP 7에 추가됨
The spaceship operator우주선 운영자 <=>
is the latest comparison operator added in PHP 7.는 PHP 7에 추가된 최신 비교 연산자입니다. It is a non-associative binary operator with the same precedence as equality operators (이것은 동등 연산자와 동일한 우선순위를 가진 비관련 이진 연산자입니다(==
, ,!=
, ,===
, ,!==
). This operator allows for simpler three-way comparison between left-hand and right-hand operands.). 이 연산자를 사용하면 왼쪽 피연산자와 오른쪽 피연산자를 3방향으로 간단하게 비교할 수 있습니다.
The operator results in an integer expression of:연산자는 다음과 같은 정수식을 생성합니다.
0
when both operands are equal양쪽 오퍼랜드가 동일한 경우- Less than 보다 적은
0
when the left-hand operand is less than the right-hand operand왼쪽 피연산자가 오른쪽 피연산자보다 작을 때 - Greater than 보다 크다
0
when the left-hand operand is greater than the right-hand operand왼쪽 피연산자가 오른쪽 피연산자보다 클 때
e.g.예.
1 <=> 1; // 0 1 <=> 2; // -1 2 <=> 1; // 1
A good practical application of using this operator would be in comparison type callbacks that are expected to return a zero, negative, or positive integer based on a three-way comparison between two values.이 연산자를 사용하는 좋은 실용적인 방법은 비교 타입의 콜백입니다.이 콜백은 2개의 값 간의 3방향 비교를 바탕으로 제로, 마이너스 또는 양의 정수를 반환할 것으로 예상됩니다. The comparison function passed to usort
is one such example.전달된 비교 함수는 이러한 예 중 하나입니다.
Before PHP 7 you would write…PHP 7 이전에는…
$arr = [4,2,1,3]; usort($arr, function ($a, $b) { if ($a < $b) { return -1; } elseif ($a > $b) { return 1; } else { return 0; } });
Since PHP 7 you can write…PHP 7부터는 쓸 수 있습니다.
$arr = [4,2,1,3]; usort($arr, function ($a, $b) { return $a <=> $b; // return $b <=> $a; // for reversing order });
_
Alias for gettext()gettext()의 에일리어스
The underscore character ‘_’ as in 밑줄 문자 ‘_’는 다음과 같습니다._()
is an alias to the gettext()
function.는 함수의 에일리어스입니다.
Syntax구문 | Name이름. | Description묘사 |
---|---|---|
x == y | Equality평등 | true if x and y have the same key/value pairsx와 y의 키/값 쌍이 동일한 경우 |
x != y | Inequality불평등 | true if x is not equal to yx가 y와 같지 않은 경우 |
x === y | Identity신원 | true if x and y have the same key/value pairsx와 y의 키/값 쌍이 동일한 경우in the same order and of the same types같은 순서로 같은 타입의 |
x !== y | Non-identity비동일성 | true if x is not identical to yx가 y와 동일하지 않은 경우 |
x <=> y | Spaceship우주선 | 0 if x is equal to y, greater than 0 if x > y, less than 0 if x < yx가 y와 같으면 0, x > y이면 0, x < y이면 0 미만 |
++x | Pre-increment프리 인크리먼트 | Increments x by one, then returns xx를 1씩 증가시킨 후 x를 반환합니다. |
x++ | Post-increment증가 후 | Returns x, then increments x by onex를 반환하고 x를 1씩 증분합니다. |
--x | Pre-decrement감소 전 | Decrements x by one, then returns xx를 하나씩 줄인 다음 x를 반환합니다. |
x-- | Post-decrement감퇴 후의 | Returns x, then decrements x by onex를 반환한 다음 x를 하나씩 감소시킵니다. |
x and y | And그리고. | true if both x and y are x와 y 둘 다true . If x=6, y=3 thenx=6, y=3이면(x < 10 and y > 1) returns 돌아온다true |
x && y | And그리고. | true if both x and y are x와 y 둘 다true . If x=6, y=3 thenx=6, y=3이면(x < 10 && y > 1) returns 돌아온다true |
x or y | Or또는 | true if any of x or y are x 또는 y 중 하나가 맞다면true . If x=6, y=3 thenx=6, y=3이면(x < 10 or y > 10) returns 돌아온다true |
x y | Or또는 | true if any of x or y are x 또는 y 중 하나가 맞다면true . If x=6, y=3 thenx=6, y=3이면(x < 3 y > 1) returns 돌아온다true |
a . b | Concatenation연결 | Concatenate two strings: “Hi” . “Ha”두 문자열을 연결합니다. “Hi” . “Ha” |