Marcus Piersen
Marcus Piersen

Reputation: 19

Splitting a string and adding to array

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 there 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!

Upvotes: 1

Views: 1206

Answers (3)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385144

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

Upvotes: 0

Fender
Fender

Reputation: 3055

just use the function explode

look at http://php.net/explode

Upvotes: 4

Michiel Pater
Michiel Pater

Reputation: 23033

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);

Upvotes: 7

Related Questions