Home >Backend Development >PHP Problem >How to create a two-dimensional array in php without assigning values
php can use an empty array to create a two-dimensional array without assigning values. The code is "$twoDimensionalArray = array()". You can use the array index in subsequent codes to assign values to the two-dimensional array.
Operating system for this tutorial: Windows 10 system, php8.1.3 version, Dell G3 computer.
In PHP, you can use an empty array to initialize a two-dimensional array, and then assign values as needed. The following is a sample code:
$twoDimensionalArray = array();
You can use the array index to assign values to the two-dimensional array in subsequent code, for example:
$twoDimensionalArray[00] = 1; $twoDimensionalArray[0][1] = 2; $twoDimensionalArray[1][0] = 3; $twoDimensionalArray[1][1] = 4;
At this time, $twoDimensionalArray
will It will be a 2x2 two-dimensional array with the following content:
array ( 0 => array ( 0 => 1, 1 => 2, ), 1 => array ( 0 => 3, 1 => 4, ), )
The assignment operation can be performed according to actual needs.
The above is the detailed content of How to create a two-dimensional array in php without assigning values. For more information, please follow other related articles on the PHP Chinese website!