php可以做陣列比較
今天無聊試著用array比較
發現竟然var_dump東西竟然是true
依我印象中Java、JavaScript都不能直接做array比較
但是php竟然可以….
太神奇了
|
|
array也可以用+法,但是+到對印的value還是以左邊為主(本身)
其實自己測試會比較清楚
The + operator returns the right-hand array appended to the left-hand array; for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored.
|
|
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”
}
array比較 === 跟 ==差別
在於===會檢查key順序
|
|
PHP: Array Operators - Manual
PHP - Check if two arrays are equal - Stack Overflow
PHP 三十天就上手-Day -17 Array Operators - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天