PHP array

PHP array

All the variables you have used have held only a single value.

An array is a special variable, which can hold more than one value at a time.

There are three types of array.

    • Indexed Array : An array with a numeric index.
    • Associative Array : Arrays with named keys.
    • Nesting Array(Multi-D array) : An array containing one or more array.

How to define array

Output:

 

1.Indexed Arrays:- There are two ways to create of indexed array.

Example:

$cars = array(“VOLVO”,”TATA”,”BMW”);

Example:

$car’s[0] = “VOLVO”;

$car’s[1] = “TATA”;

$car’s[2] = “BMW”;

  • GET the length of an array – The count() function.
  • The count() function is used to return the length (the number of elements) of an array.

Example:

Output:

2. Associative Arrays:-

  • Associative arrays are arrays that use name keys that you assign to them.
  • there are two ways to create an associative arrays.

Example:

$age = array(“peter”=>”35″,”Ben”=>”37”);

Example:

Output:

3. Multidimensional Arrays:-

  • A multidimensional Arrays is an array containing one or more arrays.

Example:

 

Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *