[Phpwm] foreach

Phil Beynon phil at infolinkelectronics.co.uk
Tue Dec 12 09:35:35 GMT 2006


> > I went for the break option, which seemed to be quite efficient
> and worked
> > just fine;
>
> I would have too; I just thought i'd try and point out there are
> alternatives...

Absolutely, which is why I asked about the possibilities of using which(),
I'm always receptive to any new ways of doing this sort of thing!

> > foreach($subdata as $nkey => $nvalue){
> > if($subdata[$nkey]['mident'] == "dummy_sub"){
> > foreach($rawdata as $rkey => $rvalue){
> > if($rawdata[$rkey]['main_index'] == $subdata[$nkey]['group_name']){
> > $subdata[$nkey]['mident'] = $rawdata[$rkey]['main_id'];
> > break;}
> > }}}
> >
>
> <snip>
>
> > All comments are appreciated.
> >
>
> Learn to indent your code? :) I find the following far easier to read -
>
>
> foreach($subdata as $nkey => $nvalue) {
>      if($subdata[$nkey]['mident'] == "dummy_sub") {
>          foreach($rawdata as $rkey => $rvalue) {
>              if($rawdata[$rkey]['main_index'] ==
>                                $subdata[$nkey]['group_name']) {
>                  $subdata[$nkey]['mident'] = $rawdata[$rkey]['main_id'];
>                  break;
>              }
>          }
>      }
> }
>
>
> Your original snippet makes it not obvious where if/foreach etc start or
> end, while when indented, I can use the positioning on the page itself,
> and not have to read every character to find out where.
>
>
> David.

I was trying to keep it from wrapping around within the email, hence adding
the various annotations everywhere. :-)

Phil




More information about the Phpwm mailing list