How do I split a string into a multidimensional array in PHP without loops?
My string is in the format "A,5|B,3|C,8"
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.
Without you actually doing the looping part, something based on
array_map+explodeshould do the trick ; for instance, considering you are using PHP 5.3 :Will get you :
Of course, this portion of code could be re-written to not use a lambda-function, and work with PHP < 5.3 — but not as fun ^^
Still, I presume
array_mapwill loop over each element of the array returned byexplode… So, even if the loop is not in your code, there will still be one…