PHP Wordpress字符串连接不起作用

The following:

class="<?php the_field('icon','service-category_'.$term->term_id) ?>">

makes it:

class="icon-ico-1"

But when I do the following:

<?php $iconpath = 'images/'.the_field('icon','service-category_'.$term->term_id).'.svg.php'; ?>

It doesn't calculate the 'icon-ico-1' and instead gives the following path:

images/.svg.php

Which is obviously not correct. I want it to be:

images/icon-ico-1.svg.php

Try storing your fields as variables and echoing the string

<?php 
  $icon = get_field('icon');
  $servicecategory = get_field('service-category_');
  $newterm = $term->term_id;
  
  echo 'images/'.$icon.'-'.$servicecategory.'-'.$newterm;
?>

</div>