Why does php says unidentified variable

Why does this result in Warning: Undefined variable $coin in C:\xampp\htdocs\test\index.php on line 16

    <?php 
        $coin = 1;
        if (array_key_exists('button1', $_POST)) {
            button1();
        }
        function button1() {
            $coin += 1; //error
            echo $coin; //error
        }
    ?>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.