PHP » PYTHON |
login |
register |
about
|
PYTHON array_walk
is this article helpful?
|
Python replacement for PHP's array_walk
[
edit
| history
]
def array_walk(dict_, func): for key, value in dict_.items(): func(value, key) def myfunction(value, key): print("The key '{0}' has the value '{1}'".format(key, value)) data = {"hello": "world"} array_walk(data, myfunction) Output: The key 'hello' has the value 'world' array_walk(PHP 4, PHP 5) array_walk — Apply a user function to every member of an array DescriptionApplies the user-defined function funcname to each element of the array array. array_walk() is not affected by the internal array pointer of array . array_walk() will walk through the entire array regardless of pointer position. Parameters
Return ValuesReturns TRUE on success or FALSE on failure. Errors/ExceptionsIf function funcname requires more parameters than given to it, an error of level E_WARNING will be generated each time array_walk() calls funcname . These warnings may be suppressed by prepending the PHP error operator @ to the array_walk() call, or by using error_reporting(). Changelog
Examples
Example #1 array_walk() example
<?php The above example will output: Before ...: d. lemon a. orange b. banana c. apple ... and after: d. fruit: lemon a. fruit: orange b. fruit: banana c. fruit: apple
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|