Re: VERY basic function question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 17 Mar 2005 10:24:31 +0200, William Stokes <kalles@xxxxxxxxxxxxx> wrote:
> I'm trying to learn functions (just started). I can't see why this fails:
> <?php
> function count($var)

You cannot use count as a function name - count() actually does
something - see the php manual

> {
> if ($var == 10){
> $result = $var + 10;
> return $result;
> }
> else {
> $result = $var + 20;
> return $result;
> }
> }
> $setvar = 10;
> count($setvar);
> echo "$result";
> ?>

This is what you may want:

<?php
function my_count($var)
{
    if ($var == 10){
        $result = $var + 10;
        return $result;
    }
    else {
    $result = $var + 20;
    return $result;
    }
}

$setvar = 10;
echo my_count($setvar);
?>


> 
> I probably just didn't understand my manual. Any ideas?
> 
> Thanks
> -Will
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux