0

I'm new to PHP and I'm trying to use ACF with Wordpress to insert this code into a specific area on my front page. Can anyone help me figure out why this function keeps returning 0?

function tjenestefunksjon() {
    $toReturn = ' ';
    if (have_rows('tjeneste')):
        $toReturn += '<ul class="tjenestelist">';
        while (have_rows('tjeneste')):
            the_row(); 
            // vars
            $ikon = get_sub_field('ikon');
            $tjenestenavn = get_sub_field('tjenestenavn');
            $tjenestebeskrivelse = get_sub_field('tjenesteinformasjon'); 
            $toReturn += '<li class="tjeneste">';
            $toReturn += '<i class="'. $ikon . '"></i>';
            $toReturn += '<p id="tjenestenavn">' . $tjenestenavn . '</p>';
            $toReturn += '<p id="tjenesteinformasjon">' . $tjenestebeskrivelse . '</p>';
            $toReturn += '</li>';
        endwhile;
        $toReturn += '</ul>';
    endif;
    return $toReturn;
} 
1
  • use .= instead of += with your $toReturn Variable Commented Nov 28, 2016 at 10:34

1 Answer 1

2

PHP uses the .= operator for concatenate, not +=.

+= Will use the Integer datatype and thus return a number, instead of the string.

Sign up to request clarification or add additional context in comments.

2 Comments

If you are happy with the answer, consider marking my Answer as solution, please.
Yes done, had to wait a few minutes until I could press it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.