Php assigns values to Arrays (two-dimensional arrays. 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, if you need to assign values to arrays in php, it is easier to assign values to one-dimensional arrays than to assign values to two-dimensional arrays or multi-dimensional arrays. next I will introduce various examples of assigning values to arrays, for more information, see.
What about PHP array assignment? As follows:
Example 1: one-dimensional array assignment
The code is as follows: |
|
$ My_array = array (); $ My_array [] = "www" $ My_array [] = "helpphp "; $ 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: |
|
$ 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: |
|
$ I = 0; While ($ result = $ db-> fetch_array ($ query )) {$ Area = $ result ["Area"]; $ Data_array [$ I] [2] = $ Area; // error! $ I = $ I + 1; } |
...