Home >Backend Development >PHP Problem >What are the two types of php arrays?

What are the two types of php arrays?

(*-*)浩
(*-*)浩Original
2019-09-17 15:16:596187browse

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";

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");

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");

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!

Statement:
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