Detailed introduction to PHP two-dimensional array assignment_PHP tutorial

WBOY
Release: 2016-07-15 13:27:33
Original
923 people have browsed it

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.

PHP itself is a simple yet powerful language. The PHP language has core features such as powerful string and array processing capabilities, and has greatly improved support for object-oriented programming (PHP5 and above). By using standard and optional extension modules, PHP applications can connect to more than a dozen databases such as MySQL or Oracle, draw, create PDF files, and create and parse XML files. You can also use C language to write your own PHP extension module. For example, provide a PHP interface function in an existing code base. You can also run PHP under Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to a database. The above is a brief introduction to PHP. Let's take a look at the relevant knowledge of PHP two-dimensional array assignment.

In ASP

<ol class="dp-xml"><li class="alt"><span><span>dim NamAre() //定义数组 </span></span></li></ol>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446520.htmlTechArticlePHP has a lot worth learning. Here we mainly introduce PHP two-dimensional array assignment. Let’s briefly summarize it first. Let’s try PHP. For ordinary computer enthusiasts, PHP may be a...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template