Xem thảo luận
Nội dung chính
- Làm thế nào để bạn mã hóa một mảng kết hợp trong PHP?
- Mảng liên kết mảng với cú pháp với ví dụ là gì?
- Đó là một ví dụ về mảng kết hợp *?
- Các mảng kết hợp trong lập trình là gì?
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận
Here array() function is used to create associative array.
xyz==>95 100==>abc 11==>100 abc==>pqr 3
Bàn luậnHere array() function is used to create associative array.
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 2Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 4Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 6Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 2Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 9Mảng liên kết được sử dụng để lưu trữ các cặp giá trị chính. Ví dụ, để lưu trữ các dấu hiệu của một môn học khác nhau của một học sinh trong một mảng, một mảng được lập chỉ mục bằng số sẽ không phải là lựa chọn tốt nhất. Thay vào đó, chúng tôi có thể sử dụng các tên chủ đề tương ứng làm các khóa trong mảng kết hợp của chúng tôi và giá trị sẽ là điểm tương ứng của chúng.
Ví dụ: Hàm mảng () ở đây được sử dụng để tạo mảng kết hợp.xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0xyz==>95 100==>abc 11==>100 abc==>pqr 7xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3xyz==>95 100==>abc 11==>100 abc==>pqr 31xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 35xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8xyz==>95 100==>abc 11==>100 abc==>pqr 39
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0____11xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 3xyz==>95 100==>abc 11==>100 abc==>pqr 7 xyz==>95 100==>abc 11==>100 abc==>pqr 8xyz==>95 100==>abc 11==>100 abc==>pqr 9xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 2
xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 71xyz==>95 100==>abc 11==>100 abc==>pqr 72
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1_______xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 74 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 83 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 18
Output:
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 92 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 01 xyz==>95 100==>abc 11==>100 abc==>pqr 75xyz==>95 100==>abc 11==>100 abc==>pqr 71Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72We can traverse associative arrays using loops. We can loop through the associative array in two ways. First by using for loop and secondly by using foreach.
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 41Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72We can traverse associative arrays using loops. We can loop through the associative array in two ways. First by using for loop and secondly by using foreach.
xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 10 xyz==>95 100==>abc 11==>100 abc==>pqr 75xyz==>95 100==>abc 11==>100 abc==>pqr 7Here array_keys() function is used to find indices names given to them and count() function is used to count number of indices in associative arrays.
xyz==>95 100==>abc 11==>100 abc==>pqr 19
Bàn luậnHere array() function is used to create associative array.
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 2Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 4Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 6Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 2Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 9Mảng liên kết được sử dụng để lưu trữ các cặp giá trị chính. Ví dụ, để lưu trữ các dấu hiệu của một môn học khác nhau của một học sinh trong một mảng, một mảng được lập chỉ mục bằng số sẽ không phải là lựa chọn tốt nhất. Thay vào đó, chúng tôi có thể sử dụng các tên chủ đề tương ứng làm các khóa trong mảng kết hợp của chúng tôi và giá trị sẽ là điểm tương ứng của chúng.
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0xyz==>95 100==>abc 11==>100 abc==>pqr 7xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3xyz==>95 100==>abc 11==>100 abc==>pqr 31xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 35xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8xyz==>95 100==>abc 11==>100 abc==>pqr 39
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0____11xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 3Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 29xyz==>95 100==>abc 11==>100 abc==>pqr 7 xyz==>95 100==>abc 11==>100 abc==>pqr 8xyz==>95 100==>abc 11==>100 abc==>pqr 9xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1xyz==>95 100==>abc 11==>100 abc==>pqr 2
xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 71xyz==>95 100==>abc 11==>100 abc==>pqr 72
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1_______xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 74 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 0xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 83 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 0xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 3xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 92 xyz==>95 100==>abc 11==>100 abc==>pqr 75
xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 29Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 72Output:
xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 01 xyz==>95 100==>abc 11==>100 abc==>pqr 75xyz==>95 100==>abc 11==>100 abc==>pqr 7Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 41Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 5xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72We can traverse associative arrays using loops. We can loop through the associative array in two ways. First by using for loop and secondly by using foreach.
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 41Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 721Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 3
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 74xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 76xyz==>95 100==>abc 11==>100 abc==>pqr 3Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 74Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 79Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 80xyz==>95 100==>abc 11==>100 abc==>pqr 72Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 74Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 83Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 74xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 80Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 87Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 88xyz==>95 100==>abc 11==>100 abc==>pqr 72xyz==>95 100==>abc 11==>100 abc==>pqr 70 xyz==>95 100==>abc 11==>100 abc==>pqr 10 xyz==>95 100==>abc 11==>100 abc==>pqr 75xyz==>95 100==>abc 11==>100 abc==>pqr 7
xyz==>95 100==>abc 11==>100 abc==>pqr 1Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 8xyz==>95 100==>abc 11==>100 abc==>pqr 79xyz==>95 100==>abc 11==>100 abc==>pqr 80xyz==>95 100==>abc 11==>100 abc==>pqr 72Here array_keys() function is used to find indices names given to them and count() function is used to count number of indices in associative arrays.
xyz==>95 100==>abc 11==>100 abc==>pqr 08xyz==>95 100==>abc 11==>100 abc==>pqr 18
Output:
xyz==>95 100==>abc 11==>100 abc==>pqrLooping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98
Looping using foreach: Student one got 95 in Maths Student one got 90 in Physics Student one got 96 in Chemistry Student one got 93 in English Student one got 98 in Computer Looping using for: Maths 95 Physics 90 Chemistry 96 English 93 Computer 98 07xyz==>95 100==>abc 11==>100 abc==>pqr 72PHP // Ví dụ về mảng kết hợp $ family = mảng ("cha" => "mohan", "mẹ" => "sita", "con trai" => "raj", "con gái" => "mona"); // Phương thức đầu tiên để đi qua mảng kết hợp foreach ($ family as $ key => $ value) {echo $ key. ' là '. $ giá trị; echo ''; }?>foreach($family as $key=>$value) { echo $key .' is '.$value; echo ''; } ?>foreach($family as $key=>$value) { echo $key . ' is '. $value; echo '
'; } ?>
Mảng số - một mảng có chỉ số số.Các giá trị được lưu trữ và truy cập theo kiểu tuyến tính.Mảng liên kết - một mảng có chuỗi là chỉ mục.Điều này lưu trữ các giá trị phần tử kết hợp với các giá trị chính thay vì theo thứ tự chỉ mục tuyến tính nghiêm ngặt.
Mảng liên kết được sử dụng để lưu trữ các cặp giá trị chính.Ví dụ, để lưu trữ các dấu hiệu của một môn học khác nhau của một học sinh trong một mảng, một mảng được lập chỉ mục bằng số sẽ không phải là lựa chọn tốt nhất.to store the marks of different subject of a student in an array, a numerically indexed array would not be the best choice.to store the marks of different subject of a student in an array, a numerically indexed array would not be the best choice.
Trong khoa học máy tính, một mảng kết hợp, bản đồ, bảng ký hiệu hoặc từ điển là một loại dữ liệu trừu tượng lưu trữ một bộ sưu tập các cặp (khóa, giá trị), sao cho mỗi khóa có thể xuất hiện nhiều nhất một lần trong bộ sưu tập.an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection.an abstract data type that stores a collection of (key, value) pairs, such that each possible key appears at most once in the collection.