First custom field value (out of several) displayed twice after query

I managed to fix it! As I suspected it had nothing to do with the code relating to $number, but rather the echo call before it.

My initial code looked like this (I’m skipping part of the loop content to keep it simple):

echo '<p style="color:grey;font-size:11px;margin:0;">(' . 

$number = intval(get_post_meta(get_the_ID(), 'number', true)); 
    if($number > 1){
        echo $number . 'x';
    }

echo ')</p>';

If $number = 1 it would display $number and if $number > 1 ) it would display $number . $number . 'x'

Looking through the code here some time later I noticed something off. In my first echo call I finish with an . so the following code could be added in my paragraph. But when finishing up the paragraph I added a new echo call instead of following up the loop code with . '</p>'.

What I did to fix it was to end my initial echo call instead of continuing it, so to fix it I only had to change one character and remove a space in the first line, so it looks like this:

echo '<p style="color:grey;font-size:11px;margin:0;">(';

Note the ending of that piece of code compared to how it looked before I fixed it. I simply replaced . with ;.

I don’t know enough php to explain this behavior, although I assume it’s got something to do with not ending/closing the echo properly. If someone else can explain more accurately, please feel free to add a comment and I’ll update this answer accordingly.