Indexing Arrays PHP

So far we've only seen arrays indexed by integers, but it is also permissible to use strings. Sometimes these are called associative arrays, or hashes. They are helpful in situations where you are collecting different types of information into one array. You could build into your code a system where element zero is a name, element one is a location, and element two is an occupation. is a more elegant way to accomplish this.

Adding to an Array

Adding to an Array

Since we aren't indexing the array with integers, we can't just pull out each value starting at zero. If you've turned ahead briefly to skim the array functions in, you may have noticed functions like reset, next, and current. These functions offer one way to step through an array, and they are the best way if you need to do more than simply step through the array in order. You can also use the each function. However, PHP 4 added a new statement called foreach specifically for stepping through an array.It is like a for loop, but esigned to pull elements from an array. You may wish to turn back and review it.

Indexing Arrays with Strings

Indexing Arrays with Strings



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics