html - Concatenate variables in single quote in php

Solution:

If it's in PHP code, you need to escape single quotes.

onclick="copy(\'' . $color->colorcode_2 . '\', this)"

Answer

Solution:

You can use template strings like this:

onclick="'copy('{$color->colorcode_2}', this)'";

Source