PHP -> Funkcie -> Array funkcie -> PHP - array
Syntax
array array(...);
Popis
Príkaz jazyka PHP
array - Create an array
Returns an array of the parameters. The parameters can be given an index with the => operator.
Note: array is a language construct used to represent literal arrays, and not a regular function.
The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.
Príklady
$fruits = array(
"fruits" => array("a"=>"orange","b"=>"banana","c"=>"apple"),
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
$arr = array
("somearray" => array
(6 => 5, 13 => 9,
"a" => 42
));
echo $arr[
"somearray"][6];
// 5
echo $arr[
"somearray"][13];
// 9
echo $arr[
"somearray"][
"a"];
// 42
$arr = array
("foo" =>
"bar", 12 => true
);
echo $arr[
"foo"];
// bar
echo $arr[12];
// 1
// Toto array je úplne rovnalé ako ...
array(5 => 43, 32, 56, "b" => 12);
// ...toto array
array(5 => 43, 6 => 32, 7 => 56, "b" => 12);
Pozri aj
list