Manual indexing of an Array in Php!
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
What is Array’s Manual indexing?
- 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.
- Syntax “index => values“, separated by commas, define index and values.
- 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.
- 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.
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.