div inside php echo

php

Solution

You can do the following:

echo '<div class="my_class">';
echo ($cart->count_product > 0) ? $cart->count_product : '';
echo '</div>';

If you want to have it inside your statement, do this:

if($cart->count_product > 0) 
{
    echo '<div class="my_class">'.$cart->count_product.'</div>';
}

You don't need the `else` statement, since you're only going to output the above when it's truthy anyway.

Problem

i have this: ``` <?php if ( ($cart->count_product) > 0) { print $cart->count_product; } else { print ''; } ?> ``` and i need to put `print $cart->count_product` inside of `<div class="my_class"></div>` I tried different ways, but i'm missing something in syntax. I'll be glad if someone could help.

Original source