[PHP-NOTES] note 130221 added to function.array-intersect

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
It preserves from the first array:
- keys
- order of elements
- duplicates

Duplicates: note that if the first array has just one value, and the other array has two of those values, only one will be returned, but in the opposite case, two will be returned.

Order of elements: it's preserved from the first array even if integer keys are out of order.

Example:
________________________________
<?php

$array1 = ['a' => 'cherry', 'b' => 'banana', 'c' => 'cherry'];
$array2 = [1 => 'banana', 0 => 'cherry', 2 => 'date'];

$result1 = array_intersect($array1, $array2);
$result2 = array_intersect($array2, $array1);

echo "Result from array_intersect(\$array1, \$array2):\n";
print_r($result1);

echo "\nResult from array_intersect(\$array2, \$array1):\n";
print_r($result2);

?>
___________________________________________
Outputs:

Result from array_intersect($array1, $array2):
Array
(
    [a] => cherry
    [b] => banana
    [c] => cherry
)

Result from array_intersect($array2, $array1):
Array
(
    [1] => banana
    [0] => cherry
)
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 161.53.254.120)
----
Manual Page -- https://php.net/manual/en/function.array-intersect.php
Edit        -- https://main.php.net/note/edit/130221
Del: integrated  -- https://main.php.net/note/delete/130221/integrated
Del: useless     -- https://main.php.net/note/delete/130221/useless
Del: bad code    -- https://main.php.net/note/delete/130221/bad+code
Del: spam        -- https://main.php.net/note/delete/130221/spam
Del: non-english -- https://main.php.net/note/delete/130221/non-english
Del: in docs     -- https://main.php.net/note/delete/130221/in+docs
Del: other reasons-- https://main.php.net/note/delete/130221
Reject      -- https://main.php.net/note/reject/130221
Search      -- https://main.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.