Check if value exists in comma separated string with PHP

php

Solution

Use `explode()` to create an array of string parts from a string, by splitting it by a certain delimiter (in this case a comma).

$HiddenProducts = explode(',',$sqlvalue);
if (in_array(2, $HiddenProducts)) {
  echo "Available";
} else {
  echo "Not available";
}

Problem

I need to check if my id exists in comma separated string. My string is saved as `"1,2,3,4,10"` in database. I have tried ``` $HiddenProducts = array($sqlvalue); if (in_array(2, $HiddenProducts)) { echo "Available"; } else { echo "Not available"; } ``` It is not working. Any solutions please...

Original source

Related problems