Jump to content

[SOLVED] I'm New To Functions -- How Do I Do This???


lotrfan

Recommended Posts

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
Share on other sites

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.