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:
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";
echo "Wild employee salary is". $ luong_nhan_vien ['wild']. "
";
echo "The salary of strong employees is". $ luong_nhan_vien ['manh']. "
";
echo "Employee salary is". $ luong_nhan_vien ['huong']. "
";
?>
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:
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.
php $diemThi = array ( "hoang" => array ( "monVatLy" => 7 , "monToan" => 8 , "monHoa" => 9 ), "manh" => array ( "monVatLy" => 7 , "monToan" => 9 , "monHoa" => 6 ), "huong" => array ( "monVatLy" => 8 , "monToan" => 8 , "monHoa" => 9 ) ); /* truy cập các giá trị của mảng đa chiều */ echo "Điểm thi môn Vật Lý của hoang là: " ; echo $diemThi [ 'hoang' ][ 'monVatLy' ] . "
" ; echo "Điểm thi môn Toán của manh là: " ; echo $diemThi [ 'manh' ][ 'monToan' ] . "
" ; echo "Điểm thi môn Hóa của huong là: " ; echo $diemThi [ 'huong' ][ 'monHoa' ] . "
" ; ?>
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:
Follow tutorialspoint
Previous article: Loop in PHP
Next lesson: String (String) in PHP