Raspberry Pi_Kor_24.4.4 PHP 연산


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


24.4.4  연산

 

PHP에서 지원하는 연산에는 다음과 같이 여러 가지가 있다.

    산술 연산

    대입 연산

    비교 연산

    증가/감소 연산

    논리 연산

    문자열 연산

    배열(Array) 연산

 

 

24.4.4.1    산술(arithmetic) 연산자

 

산술연산자는 숫자를 이용하여 일반적인 계산을 할 때 사용하는 연산자이다.

 

Operator

Description & Same as

Example

Result

+

Addition

$x + $y

Sum of $x and $y

-

Subtraction

$x - $y

Difference of $x and $y

*

Multiplication

$x * $y

Product of $x and $y

/

Division

$x / $y

Quotient of $x and $y

%

Modulus

$x % $y

Remainder of $x divided by $y

**

Exponentiation

$x ** $y

Result of raising $x to the $y'th power

 

 

 


 

24.4.4.2    대입(assignment) 연산자

 

대입연산자는 변수에 값을 지정할 때 사용하는 연산자이다. PHP에서는"=" 연산자를 사용하는데, 왼쪽 operand에 오른쪽에 있는 연산식의 결과를 지정한다.

 

Arrays에 대해서 지정 key에 대해서 값을 지정할 때는 "=>" 연산자를 사용한다

 

Operator

Description & Same as

Example

Result

x = y

The left operand gets set to the value of the expression on the right. x = y

x += y

Addition. x = x + y

x -= y

Subtraction. x = x - y

x *= y

Multiplication. x = x * y

x /= y

Division. x = x / y

x %= y

Modulus. x = x % y

 

[사용 Example]

다음은 대입연산자의 사례들이다.

 

<?php
$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4.
?>


 

24.4.4.3    비교(comparison) 연산자

 

비교연산자는 두 개의 문자 또는 숫자의 값을 서로 비교하는 연산자이다.

 

Operator

Description & Same as

Example

Result

==

Equal

$x == $y

Returns true if $x is equal to $y

===

Identical

$x === $y

Returns true if $x is equal to $y, and they are of the same type

!=

Not equal

$x != $y

Returns true if $x is not equal to $y

<> 

Not equal

$x <> $y

Returns true if $x is not equal to $y

!==

Not identical

$x !== $y

Returns true if $x is not equal to $y, or they are not of the same type

Greater than

$x > $y

Returns true if $x is greater than $y

Less than

$x < $y

Returns true if $x is less than $y

>=

Greater than or equal to

$x >= $y

Returns true if $x is greater than or equal to $y

<=

Less than or equal to

$x <= $y

Returns true if $x is less than or equal to $y

 

 


 

24.4.4.4    증가(incremental)/감소(decremental) 연산자

 

증가 연산자는 변수의 값을 1 증가시키고, 감소 연산자는 변수의 값을 1 감소시킨다.

 

Operator

Description & Same as

Example

Result

++$x

Pre-increment.

Increments $x by one, then returns $x

$x++

Post-increment.

Returns $x, then increments $x by one

--$x

Pre-decrement.

Decrements $x by one, then returns $x

$x--

Post-decrement.

Returns $x, then decrements $x by one

 


 

24.4.4.5    논리(logical) 연산자

 

논리 연산자는 두 개의 조건문을 결합하여 새로운 논리 결과를 만들어 내는 연산자이다.

 

Operator

Description & Same as

Example

Result

and

And

$x and $y

True if both $x and $y are true

or

Or

$x or $y

True if either $x or $y is true

xor

Xor

$x xor $y

True if either $x or $y is true, but not both

&&

And

$x && $y

True if both $x and $y are true

||

Or

$x || $y

True if either $x or $y is true

!

Not

!$x

True if $x is not true

 


 

24.4.4.6    문자열(string) 연산자

 

문자열 연산자는 여러 개의 문자열을 서로 연결하는 연산자이다.

 

Operator

Description & Same as

Example

Result

.

Concatenation

$txt1 . $txt2

Concatenation of $txt1 and $txt2

.=

Concatenation assignment

$txt1 .= $txt2

Appends $txt2 to $txt1

 


 

24.4.4.7    배열(array) 연산자

 

배열 연산자는 array를 비교할 때 사용되는 연산자이다.

 

Operator

Description & Same as

Example

Result

+

Union

$x + $y

Union of $x and $y

==

Equality

$x == $y

Returns true if $x and $y have the same key/value pairs

===

Identity

$x === $y

Returns true if $x and $y have the same key/value pairs in the same order and of the same types

!=

Inequality

$x != $y

Returns true if $x is not equal to $y

<> 

Inequality

$x <> $y

Returns true if $x is not equal to $y

!==

Non-identity

$x !== $y

Returns true if $x is not identical to $y

 


 

Leave a Reply