Fahdi’s Personal Blog

Here I share my web ideas

Converting comma separated integer/ digit values to an array of integers

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
September9

OK here is the code to convert a comma separated string of integer/ digit value to an array

$csvintegers='1,2,3,4,7';
$listvals=split(",",$csvintegers);
?>

You can always compare whether if an integer is present in a string or not. The code to do so is
<? if (in_array(1,$listvals)) { ?>
1 exists<br/>
<? }?>
<? if (in_array(9,$listvals)) { ?>
9 exists<br/>
<? }?>

So the above code after running one after another, will output
1 exists

So basically this code

<? if (in_array(1,$listvals)) { ?>

checks whether 1 is in the array $listvals. $listvals was created by splitting (using PHP split() function ) the comma separated string of integers ($csvintegers) with respect to commas.

Share and Enjoy:
  • Digg
  • Facebook
  • LinkedIn
  • NewsVine
  • Technorati
  • Sphinn
  • del.icio.us
  • Mixx
  • Google
  • StumbleUpon
  • Live
  • Print this article!
  • feedmelinks
  • E-mail this story to a friend!
  • Reddit
posted under PHP

Email will not be published

Website example

Your Comment: