40 likes | 144 Views
This guide explores the fundamentals of arrays in PHP, including how array keys work and the differences between indexed and associative arrays. We begin with basic array creation, noting that if no key is set, PHP auto-increments to assign keys starting from 0. We also look at unordered arrays, where specific keys can be assigned at will, followed by associative arrays that allow for named keys. Examples provided demonstrate how to access and manipulate array elements effectively, highlighting the structure and behavior of each array type.
E N D
PHP5 Array concepts
Basic Array • If you do not set the key when you create an array the initial value is 0 and then it auto increments $arr[] = “First index”; $arr[] = “Second index”; print($arr[1]); // is “Second index” print($arr[0]); // is “First index”
Array Unordered • You can specifically give an array key and not do this in a specific order $arr[12] = “First index”; $arr[9] = “Second index”; print($arr[9]); // is “Second index” print($arr[12]); // is “First index”
Associative Array • You can specifically give an array key a name $arr[‘name_first’] = “Ray”; $arr[‘name_last’] = “Gubala”; print($arr[‘name_first’]); // is “Gubala” print($arr[‘name_last’]); // is “Ray”