chan yoonghon chan yoonghon - 1 year ago 110
PHP Question

PHP: Convert string to each integer variable

I have a comma-separated string with a few integers, for example:

12 , 13 , 9

How can I convert the string above into 3 integer variables in PHP? Example:


Answer Source

Try using,

 $your_str = "12 , 13 , 9";
 $array = explode(',', $your_str);

 echo $array[0]; //12
 echo $array[1]; //13 and so on...


explode works quite similar to split() which has been deprecated. Hope it helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download