简体   繁体   中英

Understanding PHP Documentation Code

I was reading this documentation today and got confused when seeing the output.

The lines of code:

/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM);
printf ("%s (%s)\n", $row[0], $row[1]);

/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);

/* associative and numeric array */
$row = $result->fetch_array(MYSQLI_BOTH);
printf ("%s (%s)\n", $row[0], $row["CountryCode"]);

Produces the result:

Kabul (AFG)
Qandahar (AFG)
Herat (AFG)

If there's a combination of loop and data_seek() , then I can understand why the output is different each time. Shouldn't the output from the code above like this?

Kabul (AFG)
Kabul (AFG)
Kabul (AFG)

Am I missing something?

You just had to investigate a little further. The page says that this function "is an extended version of the mysqli_fetch_row()", while by following the link, you'd learn that "Each subsequent call to this function will return the next row within the result set"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM