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'); 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'); 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 .
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' Source: https://ru.stackoverflow.com/questions/626216/
All Articles