Home > Backend Development > PHP Tutorial > Introduction to knowledge related to PHP two-dimensional array assignment_PHP tutorial

Introduction to knowledge related to PHP two-dimensional array assignment_PHP tutorial

WBOY
Release: 2016-07-15 13:29:27
Original
1015 people have browsed it

We are learningFor 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

via SQL The number of records obtained from the statement query is total.

Assign value through while loop

<ol class="dp-xml"><li class="alt"><span><span>redim NamAre(total,2) //重新定义数组,其中total为查询得到的记录数  </span></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>NamAre(i,1)=rolename   </span></span></li>
<li class=""><span>NamAre(i,2)=Area  </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"><font color="#ff0000">data_array</font></span><span>=array($total,2);//其中$datarows为查询得到的记录数  </span></span></li>
<li class="alt"><span><span>$data_array[$i][2]=$Area;//提示错误:Cannot use a scalar value as an array  </span></span></li>
</ol>
Copy after login

http://www.bkjia.com/PHPjc/446359.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/446359.html

TechArticle
<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">i</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span>; </span></span></li>
<li class="alt"><span><span> while($</span><span class="attribute"><font color="#ff0000">result</font></span><span>=$db-</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>fetch_array($query)) </span></span></li>
<li class="alt"><span><span> {  $</span><span class="attribute"><font color="#ff0000">Area</font></span><span>=$result["Area"]; </span></span></li>
<li class="alt"><span><span> $data_array[$i][2]=$Area; //出错!  </span></span></li>
<li class="alt"><span><span>$</span><span class="attribute"><font color="#ff0000">i</font></span><span>=$i+1;     </span></span></li>
<li class="alt"><span><span>}   </span></span></li>
</ol>
Copy after login

We are learning. 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 PH...

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