Is there a way to avoid too many arguments when calling a function?
Eg:
function myFunction($usrName,$usrCountry,$usrDOB//and many more){
// Do something with all those arguments here
}
One way I do this is to define constants
//After thorough checking
$sesUserName = $_SESSION['sesUserName'];
define('USERNAME', $sesUserName);
myFunction(){
// Do something with USERNAME here
// No need to use USERNAME when calling the function
}
But are there other ways to do this?
$sesUserNamefrom withinmyFunction(), you can callglobal $sesUserName;as the first line inmyFunction(). This is a step up from the constant thing, but it's still generally discouraged. You can also access superglobals (the$_arrays like$_SESSION) without doing theglobalthing, so you can access$_SESSION['sesUserName']from within your function directly. This is probably not the best approach either, though. I'd recommend using an associative array, as others have pointed out.