array iteration in php
<?
$ar=array('as','ae','sd');
$ad=array("r"=>"red","o"=>"orange","b"=>"blue");
################# 1 st way###############
while($elem=current($ad))
{
print key($ad);
next($ad);
}
####################second way ############
$cur_item=current($ad);
print"<p/>". $cur_item;
while($cur_item=next($ad))
{
print"<p/>". $cur_item;
}
foreach (array_keys($ad) as $key)
{
print"<p/>".$key."==>>".$ad[$key];
}
####################Third way ############
foreach($ad as $elem)
{
print"<p/>".$elem." elem";
}
?>
No comments:
Post a Comment