Month: March 2008

made “foreach”

Posted by – March 21, 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
Share LAMP Web Development Blog:
  • Print
  • PDF
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Slashdot
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • IndianPad
  • LinkedIn
  • Live
  • MSN Reporter
  • Netvibes
  • Sphinn
  • NewsVine
  • Reddit
  • StumbleUpon
  • Technorati
  • Twitter
  • Twitthis
  • Wikio IT
  • Yahoo! Bookmarks
  • Yahoo! Buzz