array_walkNamearray_walk — Applies a specified function to each element of an array, along with optional input.DescriptionTraverses the given array and passes each element into the given function in turn. The function given as func is called once for every element of array . The function named by func can accept up to three parameters for each element: If the function named by func accepts more than three parameters, it generates a warning, unless that warning is suppressed either by using the error_reporting() function or by prepending the @ error-suppression operator to the array_walk() call. array_walk() doesn't directly alter the elements of array unless you explicitly tell it to do so, by writing the function named by func to take its first parameter by reference. ExampleExample 38. Apply a callback function to each element of an array function output_element($a) { print("Element value: $a\n"); } $arr1 = array("alpha", "baker", "charlie", "delta"); array_walk($arr1, "output_element"); Output: Element value: alpha Element value: baker Element value: charlie Element value: delta
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|