Skip to content
Advertisement

function that returns the maximum of one of several numbers and verifies whether the arguments are numbers

I am writing a function, with the name max_number, which returns the maximum of a number numbers variable. If one of the arguments is not a number, then it returns false. Using the is_numeric () function. But the function always returns false. Will I do something wrong?

The code and this:

<?php
function max_number()
{
    $args = func_get_args();
    if( $args !== null && !is_numeric($args)){
        echo "false";       
    }
    else{
        echo "Maximo number is: " . max($args);
    }
}

max_number(1,2,3,4,5);
?>

Advertisement

Answer

<?php
function max_number()
{
    $args = func_get_args();
    if( $args == null && !is_numeric($args)){
        echo "false";       
    }
    else{
        echo "Maximo number is: " . max($args);
    }
}

max_number(1,2,3,4,5);
?>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement