我有一小段PHP代码,它通过有效值并获取有关它们的信息。然后它将它推送到一个数组。出于某种原因,我只获得了$row
的最后一项,重复了几次。当我在代码中尝试print_r
#1
时,会输出预期值。但是,在循环结束时或在循环结束时,当我尝试print_r($ipArray)
时,我只会重复多次重复最后一个值。任何帮助将非常感激!
while($row = mysqli_fetch_array($getIpQuery, MYSQLI_NUM)){
for($x=0;$x<count($row);$x++)
{
$getIpInfo = mysqli_query($dbcon, "SELECT * FROM ipInfo WHERE address='$row[$x]'");
$retrievedInfo = mysqli_fetch_array($getIpInfo, MYSQLI_NUM);
$ipInfo->ipAddress = $retrievedInfo[0];
$ipInfo->portNum = $retrievedInfo[1];
print_r($ipInfo); //#1: Works perfectly fine.
array_push($ipArray,$ipInfo);
}
}
print_r($ipArray); //this is where I'm getting an output of only the last element of `$row`.
谢谢!
〜Carpetfizz