Có bao nhiêu loại mảng trong PHP 1 điểm 1 2 3 4?
Mảng trong PHP là một kiểu cấu trúc dữ liệu cho phép chúng ta lưu trữ nhiều phần tử có kiểu dữ liệu giống nhau dưới một biến duy nhất, do đó tiết kiệm công sức tạo một biến khác cho mỗi dữ liệu. Các mảng rất hữu ích để tạo danh sách các phần tử có kiểu tương tự, có thể được truy cập bằng chỉ mục hoặc khóa của chúng. Giả sử chúng tôi muốn lưu trữ năm tên và in chúng theo đó. Điều này có thể dễ dàng thực hiện bằng cách sử dụng năm biến chuỗi khác nhau. Nhưng nếu thay vì năm, con số tăng lên hàng trăm, thì người dùng hoặc nhà phát triển sẽ thực sự khó tạo ra nhiều biến khác nhau như vậy. Ở đây, mảng phát huy tác dụng và giúp chúng ta lưu trữ mọi phần tử trong một biến duy nhất và cũng cho phép truy cập dễ dàng bằng chỉ mục hoặc khóa. Mảng được tạo bằng hàm array() trong PHP Show Về cơ bản có ba loại mảng trong PHP.
Mảng được lập chỉ mục hoặc số Các loại mảng này có thể được sử dụng để lưu trữ bất kỳ loại phần tử nào, nhưng chỉ mục luôn là một số. Theo mặc định, chỉ mục bắt đầu từ số không. Các mảng này có thể được tạo theo hai cách khác nhau như trong ví dụ sau. PHP
Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV0_______0_______1 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV2 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV3 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV4 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV3 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV6 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV3 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV8 Looping using foreach: Zack Anthony Ram Salim Raghav The number of elements is 5 Looping using for: ZACK ANTHONY RAM SALIM RAGHAV3 Accessing the elements directly: zara sara any Rani Ravina0 Accessing the elements directly: zara sara any Rani Ravina1
Accessing the elements directly: zara sara any Rani Ravina2 Accessing the elements directly: zara sara any Rani Ravina3 Accessing the elements directly: zara sara any Rani Ravina4 Accessing the elements directly: zara sara any Rani Ravina5 Accessing the elements directly: zara sara any Rani Ravina3 $name_one 10_______8Accessing the elements directly: zara sara any Rani Ravina9 Accessing the elements directly: zara sara any Rani Ravina5 Accessing the elements directly: zara sara any Rani Ravina3 $name_one Looping using foreach: Husband is Zack and Wife is Zara Husband is Anthony and Wife is Any Husband is Ram and Wife is Rani Husband is Salim and Wife is Sara Husband is Raghav and Wife is Ravina Looping using for: zack zara anthony any ram rani salim sara raghav ravina3 Accessing the elements directly: zara sara any Rani Ravina9 Accessing the elements directly: zara sara any Rani Ravina5 Accessing the elements directly: zara sara any Rani Ravina3 $name_one Looping using foreach: Husband is Zack and Wife is Zara Husband is Anthony and Wife is Any Husband is Ram and Wife is Rani Husband is Salim and Wife is Sara Husband is Raghav and Wife is Ravina Looping using for: zack zara anthony any ram rani salim sara raghav ravina8 Accessing the elements directly: zara sara any Rani Ravina9 Accessing the elements directly: zara sara any Rani Ravina5
Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475361 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475362 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475363 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475364 Accessing the elements directly: zara sara any Rani Ravina5 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475362 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475367 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475368 Accessing the elements directly: zara sara any Rani Ravina5 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475362 Dave Punk mob : 2584369721 email : [email protected] John Flinch mob : 9875147536 email : [email protected]1 Dave Punk mob : 2584369721 email : [email protected] John Flinch mob : 9875147536 email : [email protected]2 Accessing the elements directly: zara sara any Rani Ravina5 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475362 Dave Punk mob : 2584369721 email : [email protected] John Flinch mob : 9875147536 email : [email protected]5 Dave Punk mob : 2584369721 email : [email protected] John Flinch mob : 9875147536 email : [email protected]6 Accessing the elements directly: zara sara any Rani Ravina5 Dave Punk email-id is: [email protected] John Flinch mobile number is: 98751475362 Dave Punk mob : 2584369721 email : [email protected] John Flinch mob : 9875147536 email : [email protected]9 0 |