PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 26, 2022

[FIXED] How to output foreach inside echo

 August 26, 2022     php, wordpress     No comments   

Issue

I need to output inside echo foreach to output the terms that belong to this post. How can i do this? The code I wrote is not working.

$cur_terms = get_the_terms( $ajaxposts->post->ID, 'cities' ); 

 echo '<div class="speaker-city">
        '. foreach( $cur_terms as $cur_term ): .'
         <p>
            '. echo $cur_term->name .'      
         </p>
         '.endforeach; .' 
       </div>';


Solution

You have to use foreach block and print inside the block

$cur_terms = get_the_terms( $ajaxposts->post->ID, 'cities' ); 

echo '<div class="speaker-city">';
foreach( $cur_terms as $cur_term )
{
    echo'<p>'. $cur_term->name .'</p>';
}
echo'</div>';


Answered By - ManiMuthuPandi
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing