0

Hello i have problem with the odd or even, i want to do function on that i have this and im getting error: Parse error: syntax error, unexpected 'spocti' (T_STRING), expecting '(' in C:\xampp\htdocs\functions.php on line 34 i have this code

<form method= "post" action= "">
    <input type= "text" name= "cislo" />
    <input type= "submit" name= "submit" />
 </form>

    <?php
        if (isset($_POST['cislo'])){

            $cislo = $_POST['cislo'];

            function spocti(){
                if ($cislo % 2 == 0)
                return true;
            }
        }
        if (function spocti == true){
            echo "Its even";
        }
     ?>
StarScrime
  • 29
  • 1
  • 2
  • 9
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Rizier123 Feb 21 '15 at 18:55

1 Answers1

2

Reading the PHP manual might help:

First, your function needs to accept a value argument, otherwise the value you're testing won't be available in the scope of the function

Second, you call the function by the name that you've assigned to that function

Third, you pass the value that you want to test when you call the function

function spocti($value){
    if ($value % 2 == 0)
        return true;
    }
}

if (spocti($cislo) == true){
    echo "Its even";
}

Note that for a function that returns a Boolean true/false, you don't need to use the comparison with true in your if test

if (spocti($cislo)){
    echo "Its even";
}
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • Notice: Undefined variable: cislo in C:\xampp\htdocs\functions.php on line 30 Its even.. im getting another error .. can you help me with that i dont know where should i place isset – StarScrime Feb 21 '15 at 18:59
  • I'm guessing that you're trying to call `if (spocti($cislo)){` even if `isset($_POST['cislo'])` is false; but from your code above, $cislo is only defined if $_POST['cislo'] is true – Mark Baker Feb 21 '15 at 19:01