DomQuery::each();
Applies a runtime-created lambda function to every element within a result set. Just like the 'walk' method, you can apply any number of arguments to the lambda function. Unlike 'walk', though, you cannot currently name them. This method names them for you using a generic convention. The first parameter passed to the callback will be an array containing the following values:
array
(
'results' => &$this->Results, // Reference of the current result set of the last XPath expression
'element' => $Result, // The currently iterated element
'position' => $this->Results->key(), // The currently itereted element's position within the result set
'context' => &$this // Reference of DomQuery instance
)
All of the following examples are acceptable.
$DomQuery = new DomQuery;
$DomQuery->load($xml);
//Print the name of first node of each matched element:
$function = '$arguments = func_get_args(); echo $arguments[0][element]->nodeName;';
$DomQuery->each($function, 'arg_one', 'arg_two');
The arguments valued 'foo' and 'bar' will be accessed within the lambda function as '$param1' and '$param2' respectively. This may change in future versions or when PHP 5.3.x is more widely-used.
Definition:
public function each($function)
Parameters:
| Name | Type | Description |
|---|---|---|
| $function | String | Content of the function to execute. |