Home > Article > Backend Development > What is the use of array function in php
The role of the array function in php: The array() function is used to create an array. For example, if we want to create an index array, the syntax is [array(value1,value2,value3]. If we want to create an empty array, the code is [$new = array()].
The array() function in php is used to create an array.
(Recommended tutorial: php video tutorial)
array() creates an array, With keys and values. If the key is omitted when specifying the array, an integer key is generated. This key starts from 0 and increases by 1.
To create an associative array using array(), you can Use => to separate keys and values.
To create an empty array, pass no arguments to array():
$new = array();
Syntax:
Index Syntax for arrays:
array(value1,value2,value3,etc.);
Syntax for associative arrays:
array(key=>value,key=>value,key=>value,etc.);
Parameters:
key Specifies the key name (numeric value or string) .
value Specifies the key value.
Example:
Create an associative array named $age:
<?php $age=array("Bill"=>"60","Steve"=>"56","Mark"=>"31"); echo "Bill is " . $age['Bill'] . " years old."; ?>
Related recommendations: php training
The above is the detailed content of What is the use of array function in php. For more information, please follow other related articles on the PHP Chinese website!