Home  >  Article  >  Backend Development  >  What is a one-dimensional array in php? Detailed explanation of one-dimensional array examples in php

What is a one-dimensional array in php? Detailed explanation of one-dimensional array examples in php

黄舟
黄舟Original
2017-05-04 09:46:086582browse

What is a PHP one-dimensional array?

A one-dimensional array is a single-structured array composed of numbers arranged in a simple sorting structure. It is the basis of two-dimensional arrays and multi-dimensional arrays.

An array is a collection of several variables of the same type. The same name can be used when referencing these variables. Arrays are composed of continuous storage units. The lowest address corresponds to the first element of the array, and the highest address corresponds to the last element. The array can be one-dimensional or multi-dimensional.

php Detailed explanation of one-dimensional array examples

One-dimensional array in computer language

(1) An array is a collection of ordered data. The arrangement of data in the array follows certain rules, and the subscript represents the sequence number of the data in the array.

(2) Use an array name (such as s) and a subscript (such as 14) to uniquely determine the elements in the array. For example, s represents the score of the 15th student.

(3) Each element in the array belongs to the same data type. You cannot put different types of data (such as student grades and student gender) in the same array.

When the elements of an array are variables, the array is called a one-dimensional array. One-dimensional array is the most common array, which only stores the contents of one column.

The general form of declaring a one-dimensional array is:

What is a one-dimensional array in php? Detailed explanation of one-dimensional array examples in php

##Example of PHP one-dimensional array:

<?php
header("Content-Type:text/html; charset=utf-8");
$array = array(1=>"PHP",2=>"中文",3=>"网");
print_r($array);
?>

The output result is:

What is a one-dimensional array in php? Detailed explanation of one-dimensional array examples in php

In the next article we will introduce "

What is a two-dimensional array in php? Detailed explanation of two-dimensional array examples in php"


[Related tutorials Recommended】

1. Relevant topic recommendations: "

php array (Array)"


The above is the detailed content of What is a one-dimensional array in php? Detailed explanation of one-dimensional array examples 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