chan yoonghon chan yoonghon - 6 days ago 7
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:

$a=12
$b=13
$c=9

Answer

Try using,

<?php
 $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!

Comments