How to use the array() function in php: The array() function is used to create an array and return it. For example, if we want to create a numerical array, the syntax is: [array(value1)]. If we want to create an associative array, the syntax is: [array(key=>value)].
array() function is used to create an array and return the created array.
(Recommended tutorial: php video tutorial)
Syntax of numerical array:
array(value1,value2,value3,etc.);
Syntax of associative array:
array(key=>value,key=>value,key=>value,etc.);
Parameters:
#key specifies the key name (numeric value or string).
#value Specifies the key value.
(Related recommendations: php training)
Example:
Create an associative array named $age:
<?php $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?>
Create multidimensional array:
<?php // 一个二维数组 $cars=array ( array("Volvo",100,96), array("BMW",60,59), array("Toyota",110,100) ); ?>
The above is the detailed content of How to use array() function in php. For more information, please follow other related articles on the PHP Chinese website!