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 Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/ 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]); Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/#findComment-364266 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. Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/#findComment-364270 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' ?> Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/#findComment-364277 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 Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/#findComment-364281 Share on other sites More sharing options...
lotrfan Posted October 8, 2007 Author Share Posted October 8, 2007 Thanks, make sense now! Link to comment https://forums.phpfreaks.com/topic/72240-solved-im-new-to-functions-how-do-i-do-this/#findComment-364284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.