dongxingguo1978 2015-02-23 14:28
浏览 55
已采纳

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.

  • 写回答

1条回答 默认 最新

  • dongshang3309 2015-02-23 14:35
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan