FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » having trouble using gd imageline in foreach loop
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: having trouble using gd imageline in foreach loop [message #172805 is a reply to message #172803] Thu, 03 March 2011 02:00 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 03/03/11 00:08, Lwangaman wrote:

> $direction = "north";

// start, direction is north

> foreach($fibsequence as $fibvalue){

// direction is north, so match this if clause

> if($direction=="north"){ $x2 = $x1; $y2 = bcsub($y1,$fibvalue); $direction="west"; }

// now direction is west, so natch this if clause

> if($direction=="west"){ $x2 = bcsub($x1,$fibvalue); $y2 = $y1; $direction="south"; }

// now direction is south, so match this if clause

> if($direction=="south"){ $x2 = $x1; $y2 = bcadd($y1,$fibvalue); $direction="east"; }

// now direction is east, so match this if clause

> if($direction=="east"){ $x2 = bcadd($x1,$fibvalue); $y2 = $y1; $direction="north"; }

// now direction is north, and we're going to start the loop again

> }

Your if tree should use else if (or switch / case, but that's another
argument):

if ($dir == "n") { /* do the north line, set $dir to w */ }
else if ($dir == "w") { /* do the west line, set $dir to s */ }
else if ($dir == "s") { /* do the south line, set $dir to e */ }
else if ($dir == "e") { /* do the east line, set $dir to n */ }

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: strange behaviour in assignment expr.
Next Topic: cookies and Firefox 3.6.15 - ugh
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 09 23:47:54 GMT 2024

Total time taken to generate the page: 0.04827 seconds