Home  >  Article  >  Backend Development  >  How to define one-dimensional array in php

How to define one-dimensional array in php

藏色散人
藏色散人Original
2019-09-17 10:08:057007browse

How to define one-dimensional array in php

One-dimensional array is a single-structured array composed of numbers arranged in a simple sorting structure. One-dimensional arrays are the most basic arrays in computer programs. Two-dimensional and multi-dimensional arrays can be regarded as generated by multiple superpositions of one-dimensional arrays.

How to define a one-dimensional array in php?

Creating arrays in PHP

In PHP, the array() function is used to create arrays:

array();

PHP Numeric array

There are two ways to create a numeric array:

Automatic assignment of ID keys (ID keys always start from 0):

$cars=array("Volvo","BMW","Toyota");

Manual assignment ID key:

$cars[0]="Volvo";
$cars[1]="BMW";
$cars[2]="Toyota";

The following example creates a numeric array named $cars, assigns three elements to the array, and then prints a text containing the array value:

Example

Output:

I like Volvo, BMW and Toyota.

Recommended tutorial:PHP tutorial

The above is the detailed content of How to define one-dimensional 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
Previous article:What format file is phpNext article:What format file is php