PHP 2D array assignment details. PHP has many things worth learning. here we mainly introduce the assignment of two-dimensional arrays in PHP. let's briefly summarize PHP. For general computer enthusiasts, PHP may be a PHP with many things worth learning. here we mainly introduce the two-dimensional PHP array assignment. let's briefly summarize PHP. For general computer enthusiasts, PHP may be a strange name. Those who are more interested in the Internet, especially those who are interested in website construction technology, may have heard of PHP. PHP is a simple but powerful programming language designed to dynamically create HTML content.
PHP itself is a simple and powerful language. PHP has core features such as powerful string and array processing capabilities, and greatly improved support for object-oriented programming (PHP5 and later versions ). 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 parsed XML files. You can also use the C language to write your own PHP extension module. For example, provide a PHP interface function in an existing code library. You can also run PHP in Windows, use COM to control other Windows applications such as Word and Excel, or use ODBC to connect to the database. The above is a brief introduction to PHP. Next let's take a look at the knowledge of assigning values to two-dimensional arrays in PHP.
In ASP
- Dim NamAre () // defines an array
The number of records obtained through SQL statement query is total.
- Redim NamAre (total, 2) // redefines the array, where total is the number of records obtained from the query.
Assign values through the while loop
- NamAre(i,1)=rolename
- NamAre(i,2)=Area
But how can we assign values to two-dimensional arrays in PHP? In PHP, I define two-dimensional arrays:
- $Data_array= Array ($ total, 2); // where $ datarows indicates the number of records obtained from the query.
- $ Data_array [$ I] [2] = $ Area; // error message: Cannot use a scalar value as an array
The specific cycle is as follows: SQL statement .......
- $I=0;
- While ($Result= $ Db->Fetch_array ($ query ))
- {
- $Area= $ Result ["Area"];
- $ Data_array [$ I] [2] = $ Area; // error!
- $I= $ I + 1;
-
- }
Bytes. For general computer enthusiasts, PHP may be...