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

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'

?>

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.