PHP

How to see if value exists in comma separated string in php


How to see if value exists in comma separated string in php

You can check if a value in a comma separated string exists in a few ways one way is:

$list = '1,2,3,4,5,6';
$commaseparatedlist = explode(',',$list);
if (in_array(2, $commaseparatedlist)) {
  echo "Available";
} else {
  echo "Not available";
}

Published: 1st June 2016 by

Adverts