Prev | Current Page 211 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Its prototype follows:
mixed reset(array array)
This function is commonly used when you need to review or manipulate an array
multiple times within a script, or when sorting has completed.
Moving the Pointer to the Last Array Position
The end() function moves the pointer to the last position of an array, returning the
last element. Its prototype follows:
mixed end(array array)
The following example demonstrates retrieving the first and last array values:
$fruits = array("apple", "orange", "banana");
$fruit = current($fruits); // returns "apple"
$fruit = end($fruits); // returns "banana"
142 CHAPTER 5 ?–  ARRAYS
Passing Array Values to a Function
The array_walk() function will pass each element of an array to the user-defined
function. This is useful when you need to perform a particular action based on each
array element. If you intend to actually modify the array key/value pairs, you??™ll need
to pass each key/value to the function as a reference. Its prototype follows:
boolean array_walk(array &array, callback function [, mixed userdata])
The user-defined function must take two parameters as input. The first represents
the array??™s current value, and the second represents the current key. If the optional
userdata parameter is present in the call to array_walk(), its value will be passed as a
third parameter to the user-defined function.
You are probably scratching your head, wondering how this function could possibly
be of any use.


Pages:
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223