Foreach's strange problem $ result = mysql_query (& quot; SELECT * FROMTB & quot;); while ($ row = mysql_fetch_array ($ result )) {/* This method successfully displays the strange question of for ($ I = 1; $ I & lt; = 5; $ I ++) foreach.
$ Result = mysql_query ("SELECT * from tb ");
While ($ row = mysql_fetch_array ($ result ))
{
/* This method can be successfully displayed
For ($ I = 1; $ I <= 5; $ I ++)
{
Echo $ row [$ I]. "| ";
}
Echo"
";
*/
Foreach ($ row as $ x)
{
Echo $ x. "| ";
}
}
I cannot understand why the data in each field is displayed twice
------ Solution --------------------
Mysql_fetch_array returns a Hybrid array of subscripts and associated arrays.
Each column in the query result must appear in the subscript array and associated array.
For loop is the part of the subscript array
While foreach loops are all
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service