PHP » PYTHON |
login |
register |
about
|
PYTHON Array Operators
is this article helpful?
|
Python replacement for PHP's Array Operators
[
edit
| history
]
array1 == array2 # equality dict1 == dict1 # equality array1 != array2 # inequality dict1 != dict2 #inequality # "+" (merge two dictionaries, latter keys NOT overwriting the former) result = dict(dict2) result.update(dict1) Array Operators
The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten.
<?phpWhen executed, this script will print the following:
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"
}
Elements of arrays are equal for the comparison if they have the same key and value.
Example #1 Comparing arrays
<?php
See also the manual sections on the Array type and Array functions. |
more
Recently updated
more
Most requested
|