Two-dimensional array assignment on PHP Details



PHP has a lot to learn, here we introduce the two-dimensional PHP array assignment, the following, a brief summary of what PHP it. For normal computer enthusiasts, PHP may be an unfamiliar name. More concerned about the network's friends, particularly concerned about the website building technology, friends, may have heard of PHP. PHP is a dynamic creation of HTML content for the design of a simple but powerful programming language.

PHP itself is a simple and powerful language. PHP language with core features such as string and array of powerful capabilities, and greatly improved support for object-oriented programming (PHP5 or later). Through the use of standard and optional expansion module, PHP applications can connect MySQL or Oracle, a dozen databases, graphics, create PDF documents and parsing XML file created. You can also use the C language to write your own PHP extension modules. For example, in the existing code base to provide a PHP interface function. You can also run Windows, PHP, use the COM control such as Word and Excel, other Windows applications, or use ODBC to connect to the database. More than the brief introduction to the PHP, let's look at two-dimensional array assignment PHP knowledge.

In the ASP in

dim NamAre () / / define array

Query SQL statement is recorded by number of total.

redim NamAre (total, 2) / / redefine the array, which total number of records for the query are

While cycling through the assignment

NamAre (i, 1) = rolename NamAre (i, 2) = Area

But how in PHP in two-dimensional array assignment? In PHP, I defined two-dimensional array:

$ Data_array = array ($ total, 2); / / where $ datarows get the number of records for the query $ data_array [$ i] [2] = $ Area; / / prompt the error: Cannot use a scalar value as an array

Specific cycle as follows: SQL statement .......

$ I = 0; while ($ result = $ db-> fetch_array ($ query)) ($ Area = $ result ["Area"]; $ data_array [$ i] [2] = $ Area; / / error ! $ i = $ i +1;)