如何从数据库PHP中的数据中获取变量中的某些字符

I have database table named tb_value below. Each row have multiple value separated by comma(s).

enter image description here

I have a variable like this and these value will be checked to tb_value :

$input = 'D1,D2,TD,GD,GD,NS';

The question is, I want to check if a row contain these value :

D1,D2,TD

The result should be showing the row with id = 2. How can I do that from Laravel 5.2 ?

If I understand your question, you could use the php explode method

$inputs = explode(",", $input);

This returns an array of all the values separated by the comma. You could take the first three values and concatenate them to get your new input.

$input_new = $inputs[0] . "," . $inputs[1] . "," . $inputs[2];

If you want to take some of these values dynamically, you should be more specific on what you want and on the structure of your code.