Creates an array from the parameters given.
This function takes a number of parameters to use as elements and returns an array with those elements. It can be used both for indexed and associative arrays.
<?php
$fruit = array("apple", "orange", "banana");
$fruit[3] = "pear";
$fruit[] = "peach";
$couples = array("Jonathan" => "Mindy",
"Adam" => "Danielle",
"Joe" => "Pamela");
$couples["Donald"] = "Daisy";
for ($i = 0; $i < sizeof($fruit); $i++) {
print "$fruit[$i] ";
}
print "<br><br>";
$wife = current($couples);
do {
print key($couples) . " & $wife <br>";
} while ($wife = next($couples))
?>
apple orange banana pear peach
Jonathan & Mindy
Adam & Danielle
Joe & Pamela
Donald & Daisy
This example shows how both associative and index arrays can be created with array(). It also demonstrates a couple of methods for adding elements.