Why is the following array() passed into a function. I am not able to understand the array() function.
I know if $_POST doesn’t have any value, it will pass array(), but what is the value in array()?
SomeFunction($_POST ? $_POST : array());
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
array()isn’t a function per se, it’s a language construct. But simply usingarray()will create an empty array for you, that is, with zero elements.You probably want to check for:
Edit:
As pointed out by greg,
$_POSTwill always be set. So there is no need to check for it and return an empty array.someFunc($_POST)should do exactly the same thing.