ID:               33887
 Updated by:       [EMAIL PROTECTED]
 Reported By:      jestrada at webmedia dot com dot mx
-Status:           Open
+Status:           Feedback
 Bug Type:         Arrays related
 Operating System: Win
 PHP Version:      5.0.4
 New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

I don't see any calls to array_diff() in your code.


Previous Comments:
------------------------------------------------------------------------

[2005-07-27 17:35:59] jestrada at webmedia dot com dot mx

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;
}




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33887&edit=1

Reply via email to