I’m curious if PHP can handle code like this, or if I’m using the wrong syntax:
$someString = implode(', ', function(){
return array('a', 'b', 'c');
});
With the desired output being a, b, c.
I’m using PHP version 5.3.3.
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.
The second parameter to
implode()takes an array, so you have to immediately execute the closure:It would arguably be nicer to have this:
But that causes a parse error.
Another acceptable way: