/ * The second method for creating arrays in PHP. * / $ numbers [0] = "one"; $ numbers [1] = "two"; $ numbers [2] = "three"; $ numbers [3] = "four"; $ numbers [4] = "five";
foreach ($ numbers as $ value) { echo "The array element value is $ value "; } ?>
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
Combined array in PHP
Complex arrays are quite similar to feature arrays, but they are different in terms of indexes. The federated array will have a string index so that you can set a strong link between the key and the value .
To store employee salaries in an array, an indexed array will not be the best option. Instead, we will use employee names as keys in the federated array, and value will be their corresponding pay.
Note : Do not keep the conjugate array inside double quotation marks while printing, otherwise it will not return any value.
For example
"; echo "The salary of strong staff is". $ luong_nhan_vien ['manh']. " "; echo "The salary of the employee is". $ luong_nhan_vien ['huong']. " ";
/ * The second method for creating conjugate arrays. * / $ luong_nhan_vien ['wild'] = "high"; $ luong_nhan_vien ['manh'] = "medium"; $ luong_nhan_vien ['huong'] = "low";
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result:
Multidimensional array in PHP
In a multidimensional array, each element can also be an array. And each element in an extra array can be an array, and so on. Values in the diverse array are accessed using multiple indexes.
For example
In this example, we create a two-dimensional array to store the 3 subject points of 3 students.
This example is a multidimensional array, you can create an integer array in the same way.
Save the above program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php will result: