It is necessary to check the presence of a character in a digit in a string, and if it does not exist, return a string with this digit, if there is a return string without it. I use the function:
$str = '1,2,3'; function get_str($str, $check) { $pos = strpos($check, $str); if ($pos === false) { return $str . ',' . $check; } else { return $str; } } echo get_str($str, 1); echo get_str($str, 4); But it does not work correctly. Tell me how you can realize your plans.
The following code returns:
1,2,3,1 1,2,3,4 Need to:
1,2,3 1,2,3,4