search
HomeBackend DevelopmentPHP ProblemWhat is an indexed array in PHP

What is an indexed array in PHP

Aug 02, 2022 pm 08:15 PM
phpphp array

In PHP, an index array refers to an array with numbers as keys (subscripts). The subscript (key name) of the index array consists of numbers, starting from 0 by default. Each number corresponds to the position of an array element in the array. There is no need to specify it. PHP will automatically assign an integer value to the key name of the index array. It then automatically increments from this value.

What is an indexed array in PHP

The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer

Array is one of the most important data types in PHP First, it is widely used in PHP. Because PHP is a programming language with weak data types, array variables in PHP can store any number of data of any type, and can implement the functions of data structures such as heaps, stacks, and queues in other strong data types.

Array An array is an ordered set of variables, where each value is called an element. Each element is distinguished by a special identifier called a key (also called a subscript).

Each entity in the array contains two items, namely key and value. The corresponding array elements can be obtained by key value. These keys can be numeric keys or association keys. If a variable is a container that stores a single value, then an array is a container that stores multiple values.

PHP arrays are divided into two types:

  • Those with numbers as key names are called indexed arrays (Indexed Array);

  • Arrays with strings or a mixture of strings and numbers as keys are called associative arrays (Associative Array).

Index array

The subscript (key name) of the index array consists of numbers, starting from 0 by default, and each number corresponds to an array The position of the element in the array does not need to be specified. PHP will automatically assign an integer value to the key name of the index array, and then automatically increase from this value.

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$arr = array(&#39;华为&#39;,&#39;三星&#39;,&#39;vivo&#39;,&#39;oppo&#39;);
var_dump($arr);
echo &#39;数组 $arr 中的,键名为2的键值为:&#39;.$arr[2];
?>

What is an indexed array in PHP

Note: If a key name in an array is not a number, then the array is not an index array, but an associative array.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is an indexed array in PHP. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools