Jump to content

whats the difference between these two loops ??


lostnucleus

Recommended Posts

Given $data = array('net','cat','wet','bat')  then wats the difference between following these two loops ??

 

  <?php  foreach($data as $moo)?>
  <?php { ?>
       <?php echo $moo;?>
  <?php } ?>

 

and

 

  
<?php foreach($data as $moo)
{
   echo $moo;
}
?>

 

Thanks in Advance as usual  8)

Link to comment
Share on other sites

<?php  foreach($data as $moo)?>

 

Is the same as

 

<?php  foreach($data as $moo); ?>

 

Therefor $moo contains the last element (as the loops assigns the last element to $moo) and you echo out the last element. This is not a bug I just didn't see it right.

Link to comment
Share on other sites

<?php  foreach($data as $moo)?>

 

Is the same as

 

<?php  foreach($data as $moo); ?>

 

Therefor $moo contains the last element (as the loops assigns the last element to $moo) and you echo out the last element. This is not a bug I just didn't see it right.

 

nw even i can see it right thx 2  u :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.