How to split value from string and get in variables?

I tried to split value from string. How to do it in php?

$data = “1-2021, 2-2018, 3-2022”;
Output should be,
var1= “1,2,3”
var2 = “2018,2022,2022”

I’d use explode() to put it in an array, then spin through that array and use explode on each element breaking on the - to get the 2 elements, and then add each one to separate $var1Array and $var2Array. Finally, I’d use implode() on each of those arrays to create $var1 and$var2.

There may be easier ways to do it but off the top of my head I can see how that would work.

Cheers! :slight_smile:
=C=