There are many things worth learning about PHP. Here we mainly introduce PHP two-dimensional array assignment. Let’s briefly summarize PHP first. For ordinary computer enthusiasts, PHP may be an unfamiliar name. Friends who pay more attention to the Internet, especially those who pay attention to website construction technology, may have heard of PHP. PHP is a simple yet powerful programming language designed for dynamically creating HTML content.
In ASP
<ol class="dp-xml"><li class="alt"><span><span>dim NamAre() //定义数组 </span></span></li></ol>
The number of records obtained through SQL statement query is total.
<ol class="dp-xml"><li class="alt"><span><span>redim NamAre(total,2) //重新定义数组,其中total为查询得到的记录数 </span></span></li></ol>
Assignment through while loop
<ol class="dp-xml"> <li class="alt"><span><span>NamAre(i,1)=rolename </span></span></li> <li class=""><span>NamAre(i,2)=Area </span></li> </ol>
But how to implement PHP two-dimensional array assignment here? In PHP, I define a two-dimensional array:
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">data_array</font></span><span>=array($total,2);//其中$datarows为查询得到的记录数 </span></span></li> <li class=""><span>$data_array[$i][2]=$Area;//提示错误:Cannot use a scalar value as an array </span></li> </ol>
The specific loop is as follows: SQL statement....
<ol class="dp-xml"> <li class="alt"><span><span>$</span><span class="attribute">i</span><span>=</span><span class="attribute-value">0</span><span>; </span></span></li> <li class=""> <span>while($</span><span class="attribute">result</span><span>=$db-</span><span class="tag">></span><span>fetch_array($query)) </span> </li> <li class="alt"><span>{ </span></li> <li class=""> <span>$</span><span class="attribute">Area</span><span>=$result["Area"]; </span> </li> <li class="alt"><span>$data_array[$i][2]=$Area; //出错! </span></li> <li class=""> <span>$</span><span class="attribute">i</span><span>=$i+1; </span> </li> <li class="alt"><span> </span></li> <li class=""><span>} </span></li> </ol>