made “foreach”

Posted by Montu on June 05, 2008

This may sound obvious but I still want to mention it :D
<?php
$a = array(
1=>'B',
2=>'C',
3=>'D',
0=>'A',
4=>'E',
);
echo "Using for\n";
$c = count($a);
for($i=0;$i<$c;$i++){
echo $a[$i],"\n";
}
echo "Using foreach\n";
foreach($a as $k){
echo $k, "\n";
}
?>

Output is

Using for
A
B
C
D
E
Using foreach
B
C
D
A
E

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments


Fine Print: I own this domain & many more & same way I own my views, if you don't like something on my blog, I am sorry, I can't help you. In fact I am not even sorry. Ch33r5.