RE: [PHP] VERY basic function question

2005-03-17 Thread YaronKh
Hi

Dont call you function count

-Original Message-
From: William Stokes [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 17, 2005 10:25 AM
To: php-general@lists.php.net
Subject: [PHP] VERY basic function question

I'm trying to learn functions (just started). I can't see why this fails:
?php
function count($var)
{
if ($var == 10){
$result = $var + 10;
return $result;
}
else {
$result = $var + 20;
return $result;
}
}
$setvar = 10;
count($setvar);
echo $result;
?

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



Re: [PHP] VERY basic function question

2005-03-17 Thread Chris Ramsay
On Thu, 17 Mar 2005 10:24:31 +0200, William Stokes [EMAIL PROTECTED] 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



RE: [PHP] VERY basic function question

2005-03-17 Thread YaronKh
And another thing
Let say you called you function count1

Change :
count1($setvar);
to :
$result = count1($setvar);
echo $result;


-Original Message-
From: William Stokes [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 17, 2005 10:25 AM
To: php-general@lists.php.net
Subject: [PHP] VERY basic function question

I'm trying to learn functions (just started). I can't see why this fails:
?php
function count($var)
{
if ($var == 10){
$result = $var + 10;
return $result;
}
else {
$result = $var + 20;
return $result;
}
}
$setvar = 10;
count($setvar);
echo $result;
?

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