Home > Backend Development > PHP Tutorial > Types of PHP arrays - numerically indexed arrays

Types of PHP arrays - numerically indexed arrays

黄舟
Release: 2023-03-07 11:14:01
Original
4890 people have browsed it

Types of PHP arrays - numeric index array

What is a PHP numeric index array?

This is the most common array type. Most programming languages ​​have numeric index arrays

PHP numeric index arrays generally represent the position of array elements in the array. It consists of numbers, and the subscript starts from 0. The default index value of the numerical index array starts from the number 0. There is no need to specify it. PHP will automatically assign an integer value to the key name of the index array, and then automatically increase from this value. Amount, of course, you can also specify a certain location to start saving data.

Arrays can be constructed as a series of "key-value (key-value) pairs", where each pair is an item or element of the array. For each item in the array, there is a key or index associated with it. The numerical index key value is as follows:

Types of PHP arrays - numerically indexed arrays

The case of numerical index array:

<?php
header("Content-Type:text/html; charset=utf-8");
$array = array("1"=>"PHP","2"=>"中","3"=>"文","4"=>"网");   //声明数组
print_r($array);                                       //输出数组元素
echo "<br>";
echo $array[1];                                      //输出数组元素的值
echo $array[2];                                      //输出数组元素的值
echo $array[3];                                      //输出数组元素的值
echo $array[4];                                     //输出数组元素的值
?>
Copy after login

The output result is:

Types of PHP arrays - numerically indexed arrays

#The index array uses an unsigned 32-bit integer as the index number. The maximum size of the index array is 2-1, which is 4,294,967,295. If the size of the array being created exceeds the maximum, a runtime error will occur.

In the next chapter we will explain in detail "Types of PHP arrays - associative arrays"!

【Related tutorial recommendations】

1. Relevant topic recommendations: "php array (Array)"

The above is the detailed content of Types of PHP arrays - numerically indexed arrays. For more information, please follow other related articles on the PHP Chinese website!

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