英[??re?] 美[?'re?]

n.Array; queue, array; a large number; clothes

vt. Arrange; deploy troops; dress up, decorate

Third person singular: arrays Plural: arrays Present participle: arraying Past tense: arrayed Past participle: arrayed

php array() function syntax

Function: Generate an array

Syntax: Index array: array(value1, value2, value3, etc.); Associative array: array(key= >value,key=>value,key=>value,etc.);

Parameters:

ParameterDescription
key Specifies the key name (numeric value or string).
value Specifies the key value.

Description: array() creates an array with keys and values. If the key is omitted when specifying the array, an integer key is generated that starts at 0 and increments by 1. To create an associative array with array(), use => to separate the keys and values. To create an empty array, pass no arguments to array().

php array() function example

<?php
//創(chuàng)建一個(gè)索引數(shù)組
$teacher = array("西門","滅絕","無(wú)忌");
$len = count($teacher);
for ($i = 0; $i < $len; $i++)
{    
echo $teacher[$i];    
echo "<br>";
}
echo "<br>";
//創(chuàng)建一個(gè)關(guān)聯(lián)數(shù)組并輸出
$teacher = array("class" => "php中文網(wǎng)","name" => "peter","age" => "30");
echo $teacher['class']. "有個(gè)老師名字叫" .$teacher['name']. ",他有" .$teacher['age']. "歲了";
?>

Run instance?

Click the "Run instance" button to view the online instance

Output:

西門
滅絕
無(wú)忌
php中文網(wǎng)有個(gè)老師名字叫peter,他有30歲了