btwael / mammouth

Unfancy PHP
http://mammouth.boutglay.com
MIT License
214 stars 22 forks source link

foreach statement #22

Closed CezaryDanielNowak closed 10 years ago

CezaryDanielNowak commented 10 years ago

There is no such thing as foreach in mammouth. http://www.php.net/manual/en/control-structures.foreach.php

btwael commented 10 years ago

in mammouth you can use this: http://mammouth.wamalaka.com/#try:{{%0Acontact%20%3D%20[]%0Afor%20contact%20of%20contacts%0A%20%20echo%28contact%29%0A}} For doc: http://mammouth.wamalaka.com/#for

CezaryDanielNowak commented 10 years ago

For is good for arrays, not for objects/dicts

btwael commented 10 years ago

I think that foreach of PHP is always used with arrays, not with with objects/dicts, do you have any examples??

CezaryDanielNowak commented 10 years ago

Sure. For example working with object database rows:

<?php
  /* ... */
  $to_edit = mysql_fetch_object($pointer);
  foreach($to_edit as $key => $value) {
      echo "<input type='text' name='{$key}' value='" . htmlspecialchars($value, ENT_QUOTES) . "'>\n";
  }
?>
CezaryDanielNowak commented 10 years ago

additionally: break & continue are compiled to /error/ and $continue;

btwael commented 10 years ago

I have add break & continue statements now: e682a49ad176fc24f36e2d7c97d2e0cb78442b7e

Quji commented 10 years ago

+1 Any news about foreach? Its really important cause $key part and use with any iterator (includes objects). More info here - http://php.net/iterator

pwhelan commented 10 years ago

foreach is also useful for arrays with non-numeric keys.

btwael commented 10 years ago

@pwhelan, we'are working on this :) tnx you...

pwhelan commented 10 years ago

The easy solution, at least from an outside perspective, is to use foreach under the hood for 'for x of y'. That way all forms of iterators and arrays are supported.

btwael commented 10 years ago

Mammouth support now for each see documentation http://mammouth.wamalaka.com/#loops