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; } |