배열 연산자

배열 연산자

Example Name Result
$a + $b Union Union of $a and $b.
$a == $b Equality true if $a and $b have the same key/value pairs.
$a === $b Identity true if $a and $b have the same key/value pairs in the same order and of the same types.
$a != $b Inequality true if $a is not equal to $b.
$a <> $b Inequality true if $a is not equal to $b.
$a !== $b Non-identity true if $a is not identical to $b.

+ 연산자는 왼쪽 배열에 추가된 오른쪽 배열을 반환합니다. 두 배열에 모두 존재하는 키의 경우 왼쪽 배열의 요소가 사용되며 오른쪽 배열의 일치하는 요소는 무시됩니다.

                  
<?php
$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");

$c = $a + $b; // Union of $a and $b
echo "Union of \$a and \$b: \n";
var_dump($c);

$c = $b + $a; // Union of $b and $a
echo "Union of \$b and \$a: \n";
var_dump($c);

$a += $b; // Union of $a += $b is $a and $b
echo "Union of \$a += \$b: \n";
var_dump($a);
?>
                  
                

실행되면 이 스크립트는 다음을 인쇄합니다.

Union of $a and $b:
array(3) {
  ["a"]=>
  string(5) "apple"
  ["b"]=>
  string(6) "banana"
  ["c"]=>
  string(6) "cherry"
}
Union of $b and $a:
array(3) {
  ["a"]=>
  string(4) "pear"
  ["b"]=>
  string(10) "strawberry"
  ["c"]=>
  string(6) "cherry"
}
Union of $a += $b:
array(3) {
  ["a"]=>
  string(5) "apple"
  ["b"]=>
  string(6) "banana"
  ["c"]=>
  string(6) "cherry"
}
                

배열의 요소는 키와 값이 동일한 경우 비교를 위해 동일합니다.

예제 #1 배열 비교

                  
<?php
$a = array("apple", "banana");
$b = array(1 => "banana", "0" => "apple");

var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
?>
                  
                
기타