Pass variable value on css class

Hello I am using the following working code and i would like to append the value of variable $something on the class of “<div class=\“lcp-customfield\”>”

  foreach ($custom_array as $something) :
        $my_custom_field = $custom_fields[$something];
        if (sizeof($my_custom_field) > 0 ):
          foreach ( $my_custom_field as $key => $value ) :
            $lcp_customs .= "<div class=\\"lcp-customfield\\">" . $value . "</div>";

What would be the correct syntax for this?

many thanks

Same as other strings, I guess.

$lcp_customs .= '<div class="lcp-customfield"'.$something.'>' . $value . '</div>';

i get confused with the backslashes… why does my original code “<div class=\“lcp-customfield\”>” have backslashes and your code doesn’t ?

Because he starts off the string with single quote (') rather than a double quote (") which is used by css, which changes what needs escaped. If the html / css code required a single quote, then you would be doing some escaping with his code as well.

Don’t fret about that too much, as it is purely a style of coding technique. He chose one that didn’t require backslashes. If you want it to still use backslashes, you the following does exactly the same thing

$lcp_customs .= "<div class=\\"lcp-customfield" . $something . "\\">" . $value . "</div>";  

I wrote the above in a way that was very familiar to what you started with.

It could also be written like so:

$lcp_customs .= "<div class=\\"lcp-customfield{$something}\\">{$value}</div>";  

thanks a lot everyone - this is all clearer now thanks to you !