Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:57:41+00:00 2026-05-30T16:57:41+00:00

I am struggling to insert comma separated after each item, if more than one

  • 0

I am struggling to insert comma separated after each item, if more than one item.

I have all values as they should, only missing the comma.

$result = $html->link($tags[$cv], array(‘controller’=>’postTags’,’action’ => ‘view’, $post_tags[$ck]), array(‘title’=>’Vis artikler under ‘.$tags[$cv],’escape’ => false));
echo $result = substr($result,0,-2);

This output correct links without comma: test1test2test3 if multiple => should be; test1, test2, test3

Also if only 1 item => output should be test1 (no comma).

So, code as is, does output correct links, but no comma! I am not sure how to proceed, any suggestions?

Tried implode (full-code using cake 1.3);

$ci = 0;
    $post_tags = explode(",", $content['Post']['tag_id']);
        if(!empty($post_tags)){
            foreach($post_tags as $ck => $cv) { 
                if(isset($tags[$cv])){
                    $ci = $ci+1;
                    $result = $html->link($tags[$cv], array('controller'=>'postTags','action' => 'view', $post_tags[$ck]), array('title'=>'Vis artikler under '.$tags[$cv],'escape' => false));
                    //pr($result);
                    $commaSeparated = implode(',',$result);
                    echo $commaSeparated;
                }
            }
        } else {
            echo '';
        }

Give me error.. ;//

pr($post_tags);

Array
(
    [0] => 3
    [1] => 1
    [2] => 2
)

pr($tags);

Array
(
    [1] => Tag1
    [2] => Tag2
    [3] => Tag3
    [4] => Tag4
)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:57:42+00:00Added an answer on May 30, 2026 at 4:57 pm

    UPDATE

    // get only the tags assigned to the post
    $postTagKeys = array_flip($post_tags);
    $tags = array_intersect_key($tags, $postTagKeys);
    
    // ok lets make the links:
    $tagLinks = array();
    
    foreach($tags as $tagId => $tagName) {
       $tagLinks[] = $html->link(
           $tagName,
           array('controller'=>'postTags','action' => 'view', $tagId),
           array('title'=>'Vis artikler under '.$tagName,'escape' => false)
    
       );
    }
    
    //$tagLinks is now an array of html <a> tags linking to individual tags
    // so to ouput the list we do
    
    echo implode(', ', $tagLinks);
    

    If you have the categories as an array just use implode:

    $cats = array('test1','test2','test3');
    $cats2 = array('test1');
    
    echo implode(', ',$cats);
    echo implode(', ',$cats2);
    

    So using your example code:

             foreach($post_tags as $ck => $cv) { 
                if(isset($tags[$cv])){
                    $ci = $ci+1;
                    $taglist = implode(', ', $tags[$cv]);
                    $result = $html->link($taglist, array(
                      'controller'=>'postTags',
                      'action' => 'view', 
                      $post_tags[$ck]  // are you sure you want to pass the array here and not just the array key?
                    ), array(
                      'title'=>'Vis artikler under '.$taglist,
                      'escape' => false)
                    );
    
                    echo $result;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am struggling on something that, I am sure, should be easy. I have
Hi all i have been struggling this for a while now! I have some
Really been struggling with this one for some time now, i have many text
I have been struggling with this for hours. My SQLite insert always returns -1
Struggling with styling the mouse over for a button ... I have managed to
Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
been struggling with an issue now for a day or two. I have an
I'm struggling to find the right terminology here, but if you have jQuery object...
I'm struggling to implement ACL in CakePHP. After reading the documentation in the cake
I have been struggling with this seeminly easy problem for 48 hours, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.