Head
Head

Reputation: 568

Inside of a ternary php script how do i concatenate a second variable into my string?

Before style="style="color: ' . $rx_event_colors . '" I want to add the $ima variable. it's just a variable with an image inside of the string. Additionally, if you think i would benefit from just adding the

 if(!empty($ins_event))
            {
            echo "<tr><td>&nbsp; <a href='". matry::here(array('event_id'=>$ins_event['id'])) . "'" . 
            ( $ins_event['status'] == 2 ? ' style="color: ' . $rx_event_colors . '">Completed Insurance Event' : '>Active Insurance Event') . "</a></td></tr>";     

            }

I've tried:

? ' $ima, style="style="color: ' . $rx_event_colors . '"
                      style="style="color: ' . $ima, $rx_event_colors . '"
                      style="style="color: ' . ($ima), $rx_event_colors . '"
                      style="style="color: ' . ($ima), ($rx_event_colors) . '"

with no avail.

Upvotes: 3

Views: 129

Answers (1)

Sites Done Right
Sites Done Right

Reputation: 652

I'm assuming $ima is a string. To concatenate strings, use the "."

So in the first part of your ternary, if you'd like to add $ima, simply do this:

' style="color: ' . $ima . $rx_event_colors . '">Completed Insurance Event'

However, I'm confused when you say "[$ima] just a variable with an image inside of the string". Does $ima contain the path to the image itself? If so, it belongs in the SRC attribute of the img tag, not inside the STYLE attribute.

UPDATE:

Because $ima contained the entire img tag, it doesn't belong in the style atrribute. See:

' style="color: ' . $rx_event_colors . '">' . $ima . 'Completed Insurance Event'

Upvotes: 3

Related Questions