Instead of the desirable result I get:
“Fatal error: Cannot redeclare count() in C:\wamp\www\counter.php on
line 25”
What actually I am doing wrong?
function count( )
{
static $count = 0;
$count++;
return $count;
}
// should print 1
print count( );
// should print 2
print count( );
The
countfunction is already defined in PHP (see the manual), which is why PHP complains that you have redeclared it.If you change the name of your function it should work.