Introduction to PHP 2D array assignment

Source: Internet
Author: User

We are learningFor 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. {$Area= $ Result ["Area"];
  4. $ Data_array [$ I] [2] = $ Area; // error!
  5. $I= $ I + 1;
  6. }

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.