在JavaScript中将单个字符串拆分为多个单独的变量
问题描述:
I have a page in php in which there is a roll number field that will be retrieved from the database like "$rollno"
now the problem is that i want to split The "$rollno" into individual character and store them in individual arrays.
Like if the roll no is 204cs10001
i want 2 to assigned to a variable and 0 to a variable and 4 to a variable and c to a variable and s to a variable and so on till the last
and i have to use the "c" and "s" variable for some comparison
Please help me out
答
you can use str_split
in php to split character from string
$str = "Hello world";
$char_arry = str_split($str);
Then you will get
Array
(
[0] => H
[1] => e
[2] => l
[3] => l
[4] => o
[5] =>
[6] => w
[7] => o
[8] => r
[9] => l
[10] => d
)