[Phpwm] foreach
David Goodwin
david at codepoets.co.uk
Tue Dec 12 07:52:53 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...
>
> 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.
More information about the Phpwm
mailing list