What are the two types of php arrays?

(*-*)浩
Release: 2023-02-24 10:00:02
Original
6080 people have browsed it

What are the two types of php arrays?

What is an array?

Array is a special variable that can save more than one value at the same time. (Recommended learning: PHP Programming from Beginner to Master)

If you have a list of items (such as a list of car brands), storing these brand names in a single variable is like this:

$cars1="porsche";
$cars2="BMW";
$cars3="Volvo";
Copy after login

However, what if you want to iterate through the variables and find a specific value? Or what if you need to store 300 car makes instead of 3?

The solution is to create an array!

Arrays can store many values ​​in a single variable name, and you can access a value by referencing an index number.

PHP Index Array

There are two ways to create an index array:

The index is automatically assigned (index starts from 0):

$cars=array("porsche","BMW","Volvo");
Copy after login

PHP Associative Arrays

An associative array is an array using specified keys that you assign to the array.

There are two ways to create associative arrays:

$age=array("Bill"=>"35","Steve"=>"37","Elon"=>"43");
Copy after login

The above is the detailed content of What are the two types of php arrays?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!