ok this may seem stupid but i just spent about an hour trying to get php to pass a variable to a function. Can someone tell me why this doesnt work ?
<?php
$num ="10";
function square ($num)
{
return $num * $num;
}
echo "$num";
?>
php function
Moderator: General Moderators
you have to call the function:
Code: Select all
$num ="10";
function square ($num)
{
return $num * $num;
}
echo square($num);-
after_shox
- Forum Newbie
- Posts: 13
- Joined: Wed Mar 10, 2004 11:53 am
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
Assign it to a variable, or just use the function call wherever you'd use a variable:after_shox wrote:how to i get the value back
Code: Select all
$num ="10";
function square ($num)
{
return $num * $num;
}
$returned_value = square($num);
echo $returned_value;
if (square(5) == 25)
{
echo "yep";
}-
after_shox
- Forum Newbie
- Posts: 13
- Joined: Wed Mar 10, 2004 11:53 am