PHP 2D array assignment details _ PHP Tutorial

Source: Internet
Author: User
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

 
 
  1. Dim NamAre () // defines an array

The number of records obtained through SQL statement query is total.

 
 
  1. Redim NamAre (total, 2) // redefines the array, where total is the number of records obtained from the query.

Assign values through the while loop

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

But how can we assign values to two-dimensional arrays in PHP? In PHP, I define two-dimensional arrays:

 
 
  1. $Data_array= Array ($ total, 2); // where $ datarows indicates the number of records obtained from the query.
  2. $ Data_array [$ I] [2] = $ Area; // error message: Cannot use a scalar value as an array

The specific cycle is as follows: SQL statement .......

 
 
  1. $I=0;
  2. While ($Result= $ Db->Fetch_array ($ query ))
  3. {
  4. $Area= $ Result ["Area"];
  5. $ Data_array [$ I] [2] = $ Area; // error!
  6. $I= $ I + 1;
  7. }

Bytes. For general computer enthusiasts, PHP may be...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.