Chapter 6 Answers
A numeric array can be indexed numerically using numbers or numeric variables. An associative array uses alphanumeric identifiers to index elements.
The main benefit of the
array
keyword is that it enables you to assign several values at a time to an array without repeating the array name.Both the
each
function and theforeach...as
loop construct return elements from an array; both start at the beginning and increment a pointer to make sure the next element is returned each time, and both returnFALSE
when the end of the array is reached. The difference is that theeach
function returns just a single element, so it is usually wrapped in a loop. Theforeach...as
construct is already a loop, executing repeatedly until the array is exhausted or you explicitly break out of the loop.To create a multidimensional array, you need to assign additional arrays to elements of the main array.
You can use the
count
function to count the number of elements in an array.The purpose of the
explode
function is to extract sections from a string that are separated by an identifier, such as extracting words separated by spaces within a sentence.To reset PHPâs internal pointer into an array back to the first element, call the
reset
function.
Get Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.