Its prototype follows:
array array_keys(array array [, mixed search_value])
138 CHAPTER 5 ?– ARRAYS
If the optional search_value parameter is included, only keys matching that value will
be returned. The following example outputs all of the key values found in the $state
array:
$state["Delaware"] = "December 7, 1787";
$state["Pennsylvania"] = "December 12, 1787";
$state["New Jersey"] = "December 18, 1787";
$keys = array_keys($state);
print_r($keys);
The output follows:
Array ( [0] => Delaware [1] => Pennsylvania [2] => New Jersey )
Retrieving Array Values
The array_values() function returns all values located in an array, automatically
providing numeric indexes for the returned array. Its prototype follows:
array array_values(array array)
The following example will retrieve the population numbers for all of the states
found in $population:
$population = array("Ohio" => "11,421,267", "Iowa" => "2,936,760");
print_r(array_values($population));
This example will output the following:
Array ( [0] => 11,421,267 [1] => 2,936,760 )
Traversing Arrays
The need to travel across an array and retrieve various keys, values, or both is common,
so it??™s not a surprise that PHP offers numerous functions suited to this need. Many of
these functions do double duty: retrieving the key or value residing at the current
CHAPTER 5 ?– ARRAYS 139
pointer location, and moving the pointer to the next appropriate location.
Pages:
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220