Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

array function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php array () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 3, PHP 4, PHP 5 )

array --  Create an array

Syntax

array array ( [mixed ...] )

Returns an array of the parameters. The parameters can be given an index with the => operator. Read the section on the array type for more information on what an array is.

Note: array() is a language construct used to represent literal arrays, and not a regular function.

Syntax "index => values", separated by commas, define index and values. index may be of type string or numeric. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.

Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.

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.

Example 1. array() example

<?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")
);
?>

Example 2. Automatic index with array()

<?php
$array
= array(1, 1, 1, 1,  1, 8 => 1,  4 => 1, 19, 3 => 13);
print_r($array);
?>

The above example will output:

Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 13
    [4] => 1
    [8] => 1
    [9] => 19
)

Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.

This example creates a 1-based array.

Example 3. 1-based index with array()

<?php
$firstquarter
= array(1 => 'January', 'February', 'March');
print_r($firstquarter);
?>

The above example will output:

Array
(
    [1] => January
    [2] => February
    [3] => March
)

As in Perl, you can access a value from the array inside double quotes. However, with PHP you'll need to enclose your array between curly braces.

Example 4. Accessing an array inside double quotes

<?php

$foo
= array('bar' => 'baz');
echo
"Hello {$foo['bar']}!"; // Hello baz!

?>

See also array_pad(), list(), count(), foreach, and range().

Php array Function syntax tag

array php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php array syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online