|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-07-27 17:40 UTC] tony2001@php.net
[2005-08-04 01:00 UTC] php-bugs at lists dot php dot net
[2006-07-22 04:47 UTC] ru61 at bk dot ru
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 05:00:01 2025 UTC |
Description: ------------ the default function array_diff returns empty records in some cases. i have two arrays 1) (1),(3),(7),(9) 2) (2),(3) it must return r) (1), (7), (9), but it returns (), (), (9) i made a similar function by my self, and i had the same problem, then i review the code, and i found a line, a simple counter: if ($l_existe == false){ <b>$arr_result[$i]</b> = $st_valorComparado; $i_result++; } the var $i must be $i_result, that's why the array contains in somecases, in which the number of found elements is less than the max elements, the empty recs, because $arr_result[$i] is putting the value of $st_valorComparado in another index higher than the max of elements found. Maybe the code of the original funcion have a similar error. Reproduce code: --------------- function fcn_array_diff($arr_comparado, $arr_compararEn){ $i_maxComparado = count($arr_comparado); $i_maxCompararEn = count($arr_compararEn); $arr_result[0] = ""; $i_result = 0; for ($i=0; $i<$i_maxComparado; $i++){ $st_valorComparado = chop($arr_comparado[$i]); $l_existe = false; for ($j=0; $j<$i_maxCompararEn; $j++){ $st_valorCompararEn = chop($arr_compararEn[$j]); if ($st_valorComparado == $st_valorCompararEn){ $l_existe = true; break; } } <b>if ($l_existe == false){ $arr_result[$i_result] = $st_valorComparado; $i_result++; }</b> } return $arr_result; }