Home >Backend Development >PHP Problem >What is the use of array function in php

What is the use of array function in php

王林
王林Original
2020-09-19 16:35:233609browse

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()].

What is the use of array function in php

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[&#39;Bill&#39;] . " 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!

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