This question has already been answered:

There is a variable

$a='1,2,3,4,5'; 

How to transfer 1,2,3,4,5 from it to an array in order to get a similar array

 $array = array('1','2','3','4','5'); 

Reported as a duplicate by participants Ipatiev , fori1ton , ߊߚߤߘ , user194374, Nick Volynkin 12 Feb '17 at 10:08 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    To do this, you can use the function explode
    It breaks a line into parts according to some static delimiter:

     $a = '1,2,3,4,5'; $array = explode(',', $a); 

    For more complex cases there is a function preg_split
    It allows you to use a regular expression as a delimiter:

     $a = '1,2;3, 4, 5'; $array = preg_split('[,;]\s*', $a); 

    For the implementation of the inverse operation (gluing a string from an array) there is a function implode

     $a = implode(', ', $array); // '1, 2, 3, 4, 5'