How to use array() function in php

王林
Release: 2023-03-05 13:36:02
Original
3490 people have browsed it

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

How to use array() function in php

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

Syntax of associative array:

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.

(Related recommendations: php training)

Example:

Create an associative array named $age:

<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
echo "Peter is " . $age[&#39;Peter&#39;] . " years old.";
?>
Copy after login

Create multidimensional array:

<?php
// 一个二维数组
$cars=array
(
array("Volvo",100,96),
array("BMW",60,59),
array("Toyota",110,100)
);
?>
Copy after login

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!

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