开发者

Splitting a string and adding to array

开发者 https://www.devze.com 2023-02-20 14:09 出处:网络
I have some data that is posted from a java application to a php page. The data is posted in the form of a string of numbers, each seperated by a comma - e.g. \"1,2,3,4,5,6,7,8\". The string could hav

I have some data that is posted from a java application to a php page. The data is posted in the form of a string of numbers, each seperated by a comma - e.g. "1,2,3,4,5,6,7,8". The string could have different amounts of numbers ther开发者_JAVA技巧e is nothing definite. I know how to split the string up but how would I go about adding it to an array in PHP? I'm completely new to PHP!


You could use the function explode(). Have a look at the manual.

For example:

$str = "1,2,3,4,5,6,7,8";
$arr = explode(',', $str);


just use the function explode

look at http://php.net/explode


If you "know how to split the string up", then you already know that this process produces an array.

0

精彩评论

暂无评论...
验证码 换一张
取 消