Tommy Tommy - 1 month ago 21
PHP Question

PHP Infinite arguments after important ones

Alright so Ive got a little problem, I am basically trying to make a system where I could just do CreateUser("Name", "password", "Not bad", "Too risky");
Just as an example. Basically 2 important arguments and the rest I Want to get dynamically.

function createUser($username, $password, $comments) {
if($comments >= 1) {
echo $comments[0];
}
}

Answer

You can make the $comments variable an array.

function createUser($username, $password, $comments=array()) {
    if($comments >= 1) {
            echo $comments[0];
        }
    }
createUser("test","testpw",array("Not bad","Too risky"));