search

Home  >  Q&A  >  body text

foreach problem

Why does the foreach output name appear double (PS has only two fields)

<?
for($iCnt2 = 0; $iCnt2 < sqlsrv_num_fields($result); $iCnt2++) {
    foreach( sqlsrv_field_metadata( $result) as $v ){
        echo "<td  align=center>". $v['Name']."</td>" ;
    }
}
?>

微信图片_20210716184752.png

fggfgg1301 days ago1506

reply all(2)I'll reply

  • Kay

    Kay2021-07-22 09:11:13

    Using foreach to traverse in a for loop is equivalent to looping the traversal again. You can know the difference between for and foreach in Baidu.

    reply
    0
  • 移动用户-9601800

    移动用户-96018002021-07-19 04:43:54

    reply
    0
  • Cancelreply