Php assigns values to arrays (two-dimensional arrays)

Source: Internet
Author: User

In php, array assignment is simple. If one-dimensional array assignment is easier than two-dimensional array assignment or multi-dimensional array assignment, I will introduce various examples of array assignment, for more information, see.

What about PHP array assignment? As follows:

Example 1: One-dimensional array assignment

The Code is as follows: Copy code

$ My_array = array ();
$ My_array [] = "www"
$ My_array [] = "helpphp ";
$ My_array [] = "cn ";


Destroy An Array

The Code is as follows: Copy code

Unset ($ My_array [0];
Unset ($ My_array );


Example 2: Two-dimensional array assignment

The Code is as follows: Copy code

$ Data_array = array ($ total, 2); // $ 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:

The Code is as follows: Copy code

$ I = 0;
While ($ result = $ db-> fetch_array ($ query ))
{$ Area = $ result ["Area"];
$ Data_array [$ I] [2] = $ Area; // error!
$ I = $ I + 1;
}

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.