Concept
How do you create and index arrays in PHP?
ComputerScienceOne / Creating Arrays
"Since PHP is dynamically typed, you do not need to declare an array or specify a particular type of variable that it holds. However, there are several ways that you can initialize an array. To create an empty array, you can call the array() function. Optionally, you can provide an initial list of elements to insert into the array by providing the list of elements as arguments to the function.\n\n1 //create an empty array:\n\n2 $arr = array();\n\n3\n\n4 //create an array with elements 10, 20, 30:\n\n5 $arr = array(10, 20, 30);\n\n6\n\n7 //create an array with mixed types:\n\n8 $arr = array(10, 3.14, \"Hello\");\n\nBy default, when inserting elements, 0-indexing is used. In the three examples above, each element would be located at indices 0, 1, and 2 respectively. The usual square bracket syntax can be used to access and assign elements."
Related Ideas
- How can you iterate over indexed and associative arrays in PHP?ComputerScienceOne · Iteration
- How does PHP support and create multidimensional arrays?ComputerScienceOne · Multidimensional Arrays
- What PHP array concepts are listed in the index?ComputerScienceOne · Index
- How can two indices be used to set values in a two-dimensional PHP array?ComputerScienceOne · Multidimensional Arrays
- How do you create and populate a two-dimensional integer array?ComputerScienceOne · Dynamic Data Structures