Friday, September 7, 2012

PHP Function array()

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

ParameterDescription
keyOptional. Specifies the key, of type numeric or string. If not set, an integer key is generated, starting at 0
valueRequired. 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

Labels

AJAX (1) Answers (1) Apache (1) Array (16) bug (1) C (1) C++ (1) Calendar (1) Class (1) Commands (1) Cookies (2) Database (2) Date (7) Days (1) explode (1) File Upload (1) FILES (1) firewall (1) fix (1) Functions (26) GET (1) GMT (1) JavaScript (2) localhost (1) Mail (1) Menu (1) MYSQL (13) PERL (1) PHP (36) php.ini (1) POST (1) preg_match (1) Questions (1) Script (1) SMS (2) Solution (1) String (1) Time (5) Time Zone (1) Vista (1) Wamp Server (1) windows 7 (2) XML (1)

Popular Posts

Popular Posts