|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-08-07 06:25 UTC] hpdl at theexchangeproject dot org
array_diff was introduced in 4.0.1, but i cant get it to return the elements right.
$array1 = array ("page1", "page2", "page3", "page4");
$array2 = array ("page1", "page4");
$result = array_diff ($array1, $array2);
for ($i=0; $i < sizeof($result); $i++) {
echo $i . '-' . $result[$i] . '<br>' . "\n";
}
i am looking for a result of array('page2','page3') - but gives me array('','page2')
array_intersect returns array('page1') with the above example.. is it not meant to return array('page1','page4') ?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 11:00:01 2025 UTC |
both: array_diff() && array_intersect: not really sure whether it?s a documentation issue (unexpected behaviour) or a bug, if you try "var_dump($result);" you?ll receive array(2) { [1]=> string(5) "page2" [2]=> string(5) "page3" } that?s fine, it has preserved the keys too! (perhaps a nice feature) I think it?s like with comparing arrays with == and ===, I?d vote for a FLAG on array_diff() (and array_intersect()), indicating if it should perform an ordered _diff (_intersect)(preserving keys, usually equal or fewer matches then unordered _diff) or unordered _diff (_intersect)(flatten(resuling array begins at index 0), finds all similarities) Resum?: I think it should be transformed into a Feature/Request bug and if not changed, it should be documented.