PHP fetch_assoc返回值,循环

I have the following code that returns two associative arrays (both of which are SQL query results). It should, iteratively, compare the values in tableA to the values in tableB, and confirm that the values in A are in B. As it stands, it returns part of the results, with the other part of the results being null (and the values in the result should not be null).

  • columnName is the name of the column that is used for the query
  • y is my counter

    while($tableA = $resultA -> fetch_assoc())
    {
        $tableB = $resultB -> fetch_assoc();
        $testA[] = $tableA; 
        $testB[] = $tableB;
        $value = $testA[$y];  
        $array = $testB[$y];
    
        //var_dump($value); 
        //var_dump($array); 
        //echo "Value[y]: ".$testA[$y]."
    "; 
    
        echo $value['$columnName']."
    "; 
    
        if(in_array($value['$columnName'], $testB))
        {
            echo $columnName.": ".$value["$columnName"]." PASS, A in B
    "; 
            //echo $value["$columnName"]."
    ";
        }
        else 
        {
            echo $columnName.": ".$value["$columnName"]." FAIL, A in B
    "; 
            //echo "FAIL
    "; 
        }
    
        $y++; 
    } 
    

Does anybody have any suggestions as to how to fix this? Thanks.

array_diff_assoc() might do what you need. It should return all keys > values that are present in both arrays.