I see there's a bit of a misunderstanding how variables inside strings work.
You may have learned that anything inside single quotes is parsed as is and inside double quotes the variables' contents are printed, like so:
$foo = 'bar';
echo 'foo: $foo'; // result: foo: $foo
echo "foo: $foo"; // result: foo: bar
But, you can't combine the two methods; putting double quotes inside single quotes doesn't make the variable's contents printed. The double quotes work only if the entire string is delimited by them. Therefore the following won't work:
echo 'foo: "$foo"'; // result: foo: "$foo"
Expanding this to your case, you can just replace the single quotes with double quotes and drop the inner double quotes.
$array_keyword .= "+$ArrayKeywords[$i] ";
Also note that you have to concatenate the new words into the variable (.=
), otherwise the variable is overwritten on each loop.
Side note: it's much easier to use a foreach
loop than a for
loop when looping through arrays:
$ArrayKeywords = explode(" ", $b_keyword);
$array_keyword = '';
foreach( $ArrayKeywords as $keyword ) {
$array_keyword .= '+$keyword ";
}