0

equal lines

I search the records in a table and put them in an array. I search the records in another table and put them in another array. When the number of query rows in each table are the same, and the arrays are the same, the code is able to identify equality.

different lines

When the number of query rows in one table is different from the query in the other table, even though the arrays are the same, the code identifies it as different.


//Query1
while(){
 $vetor_xml[$cfop] += $vTotal;
}

//Query2
while(){
 $vetor_c190[$cfop] += $aux_vl_opr;
}


function identical_values( $arrayA , $arrayB ) {

    ///sort( $arrayA );
    ///sort( $arrayB );

    return ($arrayA == $arrayB);
}


$r = identical_values( $vetor_xml, $vetor_c190);
var_dump($r);

if(($vetor_xml=== $vetor_c190)==false){
 echo "ERROR";
}
else{
 echo "OK";
}

Here is link for download the code and slq data for test http://github.com/rafaelspfonseca/test

  • Row NF 475 is not working
  • Row NF 8989 is not working
  • Row NF 9139 is working
  • Row NF 9115 is not working

2 Answers2

0

Try using array_diff

$array1 = array("a" => "sky", "star", "moon", "cloud", "moon");
$array2 = array("a" => "sky", "star", "moon", "cloud", "moon");

// Comparing the values
$result = array_diff($array1, $array2);
if(empty($result)){
    //array are equal
}else{
   //array are not equal
   //you can print the difference 
}
0

Resolved! Follows solution.

function identical_values( $arrayA , $arrayB ) {

    ///sort( $arrayA );
    //sort( $arrayB );

    return ($arrayA == $arrayB);
}


$res = identical_values( $vetor_xml , $vetor_c190 );

$result = array_diff_assoc($vetor_xml, $vetor_c190);//add new verification
   
  
if(($tem_xml>0)&&(empty($res))) {

   //add new verification here
   if(empty($result)){
      echo"<p><b>EQUAL</b>";
   }
   else{
      echo "<p><b>NOT EQUAL</b>";
      $divergencia++;
   }
}

else{
    echo"<p><b>EQUAL</b>";
}