Concept
How are elements added to the next available integer index in a PHP array?
ComputerScienceOne / Removing Elements
"By using the assignment operator but not specifying the index, the element will be added to the next available integer index. Since there were already 3 elements in the array, each subsequent element is inserted at index 3, 4, and 5 respectively. In general, the element will be inserted at the maximum index value already used plus one.\n\n$arr = array(10, 20, 30);\n\n$arr[] = 5;\n\n$arr[] = 15;\n\n$arr[] = 25;\n\nprint_r($arr);\n\nThe example above results in the following.\n\nArray ( [0] => 10 [1] => 20 [2] => 30 [3] => 5 [4] => 15 [5] => 25 )"
Related Ideas
- How can you add elements to an array?ComputerScienceOne · Adding Elements
- Can PHP array indices be non-contiguous?ComputerScienceOne · Strings as Indices
- How do you create and index arrays in PHP?ComputerScienceOne · Creating Arrays
- How can key-value pairs be initialized in a PHP array?ComputerScienceOne · Non-Contiguous Indices
- How can strings be used as indices in PHP arrays?ComputerScienceOne · Non-Contiguous Indices
- How can you print the contents of a PHP array in a readable format?ComputerScienceOne · Useful Functions
- How can you iterate over indexed and associative arrays in PHP?ComputerScienceOne · Iteration
- How can you count the elements in a PHP array?ComputerScienceOne · Useful Functions