Home >>PHP Array Functions >PHP array() Function

PHP array() Function

PHP array() Function

PHP array() function is used to create an array. Arrays is a type of data structure that allow us to store multiple similar data type elements under a single variable.

Syntax:

array(value1, value2, value3,…);
		or
array(key=>value,key=>value,key=>value,…);

Parameter Values

Parameter Description
key This parameter defines the key.
value This parameter defines the value.

Here is an example of array() function in PHP:

<html>
<body>
<pre>
<?php
$a=array("abhi","jerry","PHP"); 
print_r($a);
?>
</pre>
</body>
</html>

Output:

Array
(
    [0] =>abhi
    [1] => jerry
    [2] => PHP
)

Example 2:

<html>
<body>
<pre>
<?php
$a=array("name"=>"Jerry","age"=>"21","place"=>"Delhi"); 
print_r($a);
?>
</pre>
</body>
</html>
Output:

Array
(
    [name] => Jerry
    [age] => 21
    [place] => Delhi
)

No Sidebar ads