lotrfan Posted October 8, 2007 Share Posted October 8, 2007 Hi All, Little functions question. $angle[1] = 2 //radians $angle[2] = 2 angle_finder($angle[0], $angle[1], $angle[2]); function angle_finder($find, $found, $found_2) { $find = rad2deg($find); $found = rad2deg($found); $found_2 = rad2deg($found_2); $find = 180 - $found - $found_2; $find = rad2deg($find); $found = rad2deg($found); $found_2 = rad2deg($found_2); return $find; } I'm new to functions. How do I get my "$find" variable within my function to become the 'new' value for whatever variable was put in for it? (In this case I want "$find" to become the new value for "$angle[0]") Thanks in Advance Quote Link to comment Share on other sites More sharing options...
trq Posted October 8, 2007 Share Posted October 8, 2007 $angle[0] = angle_finder($angle[0], $angle[1], $angle[2]); Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 8, 2007 Author Share Posted October 8, 2007 Sorry, I don't understand your fix... I know, I'm really new to functions, like I said. Quote Link to comment Share on other sites More sharing options...
trq Posted October 8, 2007 Share Posted October 8, 2007 In this case I want "$find" to become the new value for "$angle[0]" Your function returns $find, so assign the return value of your function to $angle[0]. Example. <?php function foo() { return 'bar'; } $a = foo(); // $a now holds 'bar' ?> Quote Link to comment Share on other sites More sharing options...
yzerman Posted October 8, 2007 Share Posted October 8, 2007 $angle[0] = angle_finder($angle[0], $angle[1], $angle[2]); This assigns $angle[0] to the value that you return with angle finder. i.e. using your example above your code returns nothing - assigning the angle[0] as thorpe stated above: <?php $angle[1] = 2; //radians $angle[2] = 2; $angle[0] = angle_finder($angle[0], $angle[1], $angle[2]); print_r($angle[0]); function angle_finder($find, $found, $found_2) { $find = rad2deg($find); $found = rad2deg($found); $found_2 = rad2deg($found_2); $find = 180 - $found - $found_2; $find = rad2deg($find); $found = rad2deg($found); $found_2 = rad2deg($found_2); return $find; } ?> returns -2817.98508769 Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 8, 2007 Author Share Posted October 8, 2007 Thanks, make sense now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.