Generate Array from a comma-separated list - PHP

arrays, php, string

Solution

Check out `explode`: `$thePostIdArray = explode(', ', $var);`

Problem

I have a variable defined like so: $var = "1, 2, 3"; & I have an array: $thePostIdArray = array(1, 2, 3); The Array above works great when looping through it but when I try to use the $var in place of the comma-separated list, problems occur. So (perfect world) it could be $thePostIdArray = array($var); which would be the same as $thePostIdArray = array(1, 2, 3);. Every attempt so far hasn't worked :'( Is this even possible, or is there an easier workaround? Thank you for any pointers.

Original source

Related problems