Question about current() and key()
| From: | Jim Lucas | Date: | Mon, 09 Jun 2003 21:38:22 +0000 |
| Subject: | Question about current() and key() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-150807@lists.php.net to get a copy of this message | ||
Does anybody know any benifits to using current() and key()
I will show two examples of what I mean.
<?php
echo "<PRE>";
$arr1 = array(array(1 => 10),
array(2 => 12),
array(3 => 13),
array(4 => 14),
array(5 => 15),
array(6 => 16),
array(7 => 17),
array(8 => 18),
array(9 => 19)
);
foreach ( $arr1 AS $value ) {
echo pow(key($value) , current($value))."\n";
}
$arr2 = array(1 => 10,
2 => 12,
3 => 13,
4 => 14,
5 => 15,
6 => 16,
7 => 17,
8 => 18,
9 => 19
);
foreach ( $arr2 AS $key => $value ) {
echo pow($key , $value)."\n";
}
?>
Now for me, these return the same results.
I would think that it would be overhead to use current() and key() in the
above example.
Can anybody point out why the first one would be better to use and why.
Jim Lucas