RSS

Optional Variable in PHP

Last time when I want to have three args I need to declare three args in each function, then when I want to have another args I really need to modify the function’s args and I need to find all the the place where my function are using. and I found it is very difficult for me. I want to have optional one where we can use how much we want by just put args in when we use function. then I found this way on the internet:

<?php
function accessibleUsers()
{
// count args in this function
$numargs = func_num_args();
echo "Number of arguments: $numargs
\n";
// Get each arg from the function
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "users $i is: " . $arg_list[$i] . "
\n";
}
}
// How many args you want depend on you. just put it when use function
accessibleUsers('pherum', 'sky walker', 'user test');
?>

 

បញ្ចេញមតិ

 
Design a site like this with WordPress.com
Get started