Manual indexing of an Array in Php!

What is Array’s Manual indexing?

  1. when we create our own indexing in an array is known manual indexing. in which we change default indexing starting from zero ‘0’ index. we can keep values in our own indexing using “=>“this operator. for example.
  2. Syntax “index => values“, separated by commas, define index and values.
  3. Index may be of type string or integer. 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.
  4. Note that when two identical index are defined, the last overwrite the first.

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, 9 =>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
)

Why we’re using array indexing?

The location of an item in an array refers indexing. The INDEX function returns a value or the reference to a value from within a table or range. There are two ways to use the INDEX function: If you want to return the value of a specified cell or array of cells, see Array form.

The basics of the array data structure

When we uses array indexing manually?

When data objects are stored in an array, individual objects are selected by an index that is usually a non-negative scalar integer. Indexes are also called subscripts. An index maps the array value to a stored object.

array Index - Pristine Tech School