Replace each() with foreach in usort and simplexmlelement/xpath

This commit is contained in:
Pierrick Charron 2022-05-26 13:16:41 -04:00
parent 6be77ad626
commit 08e0e7dd68
No known key found for this signature in database
GPG key ID: 286AF1F9897469DC
2 changed files with 3 additions and 3 deletions

View file

@ -154,7 +154,7 @@ $fruits[2]["fruit"] = "grapes";
usort($fruits, "cmp");
while (list($key, $value) = each($fruits)) {
foreach ($fruits as $key => $value) {
echo "\$fruits[$key]: " . $value["fruit"] . "\n";
}
?>

View file

@ -67,14 +67,14 @@ $xml = new SimpleXMLElement($string);
/* Search for <a><b><c> */
$result = $xml->xpath('/a/b/c');
while(list( , $node) = each($result)) {
foreach ($result as $node) {
echo '/a/b/c: ',$node,"\n";
}
/* Relative paths also work... */
$result = $xml->xpath('b/c');
while(list( , $node) = each($result)) {
foreach ($result as $node) {
echo 'b/c: ',$node,"\n";
}
?>