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

What is the use of array function in php

王林
Release: 2023-03-05 21:46:01
Original
3614 people have browsed it

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();
Copy after login

Syntax:

Index Syntax for arrays:

array(value1,value2,value3,etc.);
Copy after login

Syntax for associative arrays:

array(key=>value,key=>value,key=>value,etc.);
Copy after login

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.";
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template