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, anyone you need to know

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: assign values to one-dimensional arrays. the instance code is as follows:

  1. $ My_array = array ();
  2. $ My_array [] = "www"
  3. $ My_array [] = "helpphp ";
  4. $ My_array [] = "cn ";

Destroy an array,The code is as follows:

Unset ($ My_array [0];

Unset ($ My_array );

Example 2: Two-dimensional array assignment,The code is as follows:

  1. $ Data_array = array ($ total, 2); // $ 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. the instance code is as follows:

  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.