Syntax
| array(key1 => value1, key2 => value2...) | 
Definition and Usage
Returns an array of the parameters. The parameters can be given an index with the => operator
Paramters
| Parameter | Description | 
|---|---|
| key | Optional. Specifies the key, of type numeric or string. If not set, an integer key is generated, starting at 0 | 
| value | Required. Specifies the value | 
Return Values
Returns an array of the parameters.
Example
Try out following example
| <?php
$a=array("a"=>"Dog", "b"=>"Cat", "c"=>"Horse");
print_r($a);
?> 
 | 
This will produce following result:
| Array ( [a] => Dog [b] => Cat [c] => Horse ) | 
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.
| <?php
$fruits = array (
    "fruits" => array("a"=>orange", "b"=>banana", "c"=>apple"),
    "numbers" => array(1, 2, 3, 4, 5, 6),
    "holes" => array("first", 5 => "second", "third")
);
?>  | 
 
No comments:
Post a Comment