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:
- $ 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 instance code is as follows:
- $ I = 0;
- While ($ result = $ db-> fetch_array ($ query ))
- {$ Area = $ result ["Area"];
- $ Data_array [$ I] [2] = $ Area; // error!
- $ I = $ I + 1;
- }