Instead of specifying parameters to PHP function I want to pass string that is comma separated. However, the code below print the string as $param1.

$str = "param1, param2";

function test($param1, $param2) {
echo "\n\n\n".$param1;
}

test($str); //output the $str instead of $param1

Can I pass string to the function?

    you will have to split the string into pieces using [man]explode[/man]

      It depends on whence this string parameter comes and what the function does with it, but if it's just a matter of being able to pass an arbitrary number of arguments then there may be other (perhaps more robust) methods.

        Write a Reply...