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!