0

My code is:

$arr = array(1,2,3);
foreach ($arr as $key => $value) 
{
  $resultstr[] = "FIND_IN_SET (" .$value. ", Dotazioni) > 0";   
}
$dotazioni_camera = implode(" and ",$resultstr);
echo($dotazioni_camera);

Result is:

FIND_IN_SET (1, Dotazioni) > 0 and FIND_IN_SET (2, Dotazioni) > 0 and FIND_IN_SET (3, Dotazioni) > 0

This is correct!! But if i try to change Arr from

 $arr = array(1,2,3);

To

 $arr = array($var);

the result change in:

FIND_IN_SET (1,2,3, Dotazioni) > 0

I think that variable convert integer value separeted by comma in a string value. I looked for a possible solution but I did not find anything. I hope you can help me.

2
  • what does $var has ? Commented Dec 21, 2017 at 12:01
  • can you please share your $var value? Commented Dec 21, 2017 at 12:02

1 Answer 1

2

If you have

$var = '1,2,3';

When you call

$arr = array($var);

This is an array of 1 value - 1,2,3. If you want to have an array of values 1, 2 and 3, you will have to do something like...

$var = '1,2,3';
$arr = explode(",", $var);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.